search
top

Obj-C: UIAlert

Display a simple message to the user thus:

UIAlertView *alert =
        [[UIAlertView alloc] initWithTitle: @"Title goes here"
                             message: @"Message goes here"
                             delegate: self
                             cancelButtonTitle: @"OK"
                             otherButtonTitles: nil];
    [alert show];
    [alert release];

If you want to catch the button press :

- (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) id {
    NSLog(@"button clicked: %d", id);
}

Obj-C: performSelector instead of NSTimer

Often times I just want to delay a single call by a number of seconds. I don’t really want to loop it.

Previous I had used NSTimer to create the call, then I had to remove the time when the call was made. This was less than ideal, and more code that I would have liked. However, I’ve since discover the excellent ‘PerformSelector’:

To use:

[self performSelector:@selector(method) withObject:nil afterDelay:5.0];

To cancel:

[NSRunLoop cancelPreviousPerformRequestsWithTarget:self];

For more information, check out apples docs here: apple docs

top