Skip to content

Instantly share code, notes, and snippets.

View mike3k's full-sized avatar

Mike Cohen mike3k

View GitHub Profile
NSString *viewName = [_views objectAtIndex:indexPath.row];
Class viewclass = NSClassFromString(viewName);
if (nil != viewclass) {
UIViewController *detailView = [[viewclass alloc] initWithNibName:viewName bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
[detailView release];
}
@mike3k
mike3k / NSData+Base64.m.m
Created January 8, 2011 18:00
This is just plain wrong.
NSData *encodeData(NSData *input) {
char encodeArray[512];
memset(encodeArray, '\0', sizeof(encodeArray));
encode([input length], (char *)[input bytes], sizeof(encodeArray), encodeArray);
return [NSData dataWithBytes:encodeArray length:strlen(encodeArray)];
}
@mike3k
mike3k / login.m
Created January 16, 2011 23:11
MGSimpleNote login
- (IBAction)Login:(id)sender
{
MGSimplenoteLogin *login = [[MGSimplenoteLogin alloc] init];
loginStatus.text = @"Logging in...";
login.email = self.userName.text;
login.password = self.password.text;
[login addObserver:self forSelector:@selector(login) success:@selector(loginSucceeded:) failure:@selector(loginFailed:)];
[login login];
}
@mike3k
mike3k / MGSNObject.m
Created January 16, 2011 23:19
addObserver changed to use nil instead of self
- (void)addObserver:(id)obj forSelector:(SEL)selector success:(SEL)success failure:(SEL)failure {
[[NSNotificationCenter defaultCenter] addObserver:obj selector:success name:[self successNotificationNameForSelector:selector] object:nil];
[[NSNotificationCenter defaultCenter] addObserver:obj selector:failure name:[self failureNotificationNameForSelector:selector] object:nil];
}
NSString *CellIdentifier;
if (indexPath.row == X) && (indexPath.section == Y) {
CellIdentifier = @"CellWithSubview";
} else {
CellIdentifier = @"Cell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
@mike3k
mike3k / set size.m
Created January 21, 2011 02:02
use sizeOfString to resize a view
CGSize constraint = CGSizeMake(200000.0, 10.0);
CGSize size = [sourceLabel.text sizeWithFont:[UIFont italicSystemFontOfSize:7.0] constrainedToSize:constraint
lineBreakMode:UILineBreakModeTailTruncation];
sourceLabel.frame = CGRectMake(318.0 - size.width,
quantityPickerView.frame.origin.y,
size.width,
size.height);
@mike3k
mike3k / Share Items.m
Created May 11, 2011 01:33
Use ShareKit for individual items
- (IBAction)tweet:(id)sender
{
SHKItem *aTweet = [SHKItem text: [NSString stringWithFormat:
@"I just scored %@ in @SugarRushApp! How high can you jump? http://sugarrush-app.com/",
[UserSettings get].formattedScore]];
[SHKTwitter shareItem:aTweet];
}
- (IBAction)facebook:(id)sender
{
@mike3k
mike3k / Sugar Rush Link.m
Created May 17, 2011 00:54
App store link for sugar rush
@mike3k
mike3k / MarchingAntsView.plain_text
Created May 27, 2011 19:56
View that implements marching ants selection
@interface MarchingAntsView : NSView {
NSPoint clickLoc;
NSRect selection;
}
@end
@implementation MarchingAntsView