Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / example.m
Created November 20, 2012 18:58 — forked from henrik/example.m
Locating the keyboard (UIKeyboard) on iOS 4, to e.g. add a custom button.
- (void)someSetupMethod {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
}
- (void)someTeardownMethod {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
}
@romyilano
romyilano / ios_nav_bar_info_button.m
Created November 20, 2012 18:59 — forked from codeswimmer/ios_nav_bar_info_button.m
iOS: How to add an Info Button to the right button slot in a Navigation Bar
// This is assumed to be inside a UINavigationController
-(void)awakeFromNib
{
// How to turn a NavigationItem's rightBarButtonItem into an Info Button
// First, in your storyboard or xib add a Bar Button Item to the right slot in the navigation bar.
// Then, do this:
UIButton *infoLightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
infoLightButton.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
infoLightButton.backgroundColor = [UIColor clearColor];
[infoLightButton addTarget:self action:@selector(showInfo:) forControlEvents:UIControlEventTouchUpInside];
NSMutableArray* reversedMessages = [NSMutableArray arrayWithCapacity:[messages count]];
NSEnumerator* reverseEnumerator = [messages reverseObjectEnumerator];
for (id object in reverseEnumerator)
{
[reversedMessages addObject:Object];
}
// http://stackoverflow.com/questions/7457944/reverse-a-nsarray-worry
var Guest = Backbone.Model.extend();
var Table = Backbone.Model.extend();
var firstGuest = new Guest(guests[0]);
var GuestView = Backbone.View.extend({
initialize: function () {
this.listenTo(this.model, 'change', this.render);
},
tagName: 'h1',
UIWebView *webView = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
webView.delegate = self;
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
NSURL *htmlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"]isDirectory:NO];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
dispatch_async(queue, ^{
@romyilano
romyilano / gist:7741096
Created December 1, 2013 21:29 — forked from JaredCrawford/gist:946890
Singleton using GCD dispatch_once
+(id)singleton{
static dispatch_once_t once;
static id singleton;
dispatch_once(&once, ^ { singleton = [[self alloc] init]; });
return singleton;
}
@romyilano
romyilano / MyTableViewControllerWithSegue.m
Last active January 1, 2016 04:19 — forked from hacksoldier/Prepare For Segue
Damn, always forget this one. the selected table row for is the indexPathForSelectedRow:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
}
}
-(void)bubbleSortArray:(NSMutableArray*)unsortedArray{
while (TRUE) {
BOOL hasSwapped = NO;
for (int i=0; i<unsortedArray.count; i++){
/** out of bounds check */
if (i < unsortedArray.count-1){
- (void)setupBackButtonWithSelector:(SEL)selector {
// create a custom button
LIButton *backButton = [LIButton buttonWithType:UIButtonTypeCustom];
backButton.positionInNavBar = LIButtonNavPositionLeft;
// more back button setup
// add back button to navigation bar
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backItem;
}