Another Google Code Brain

Tuesday, September 1, 2009

UITableView Row Heigth

Use the following delegate method:
- (CGFloat)tableView:(UITableView *)tableview heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60.0f;
}

Reference: jpm@stackoverflow.com

Stop iPhone from going to sleep

"The code below will prevent the iPhone from dimming its screen and ultimately going to sleep. Use it wisely as you don’t want your application becoming notorious for being a battery hog :)"

     [UIApplication sharedApplication].idleTimerDisabled = YES;

Reference: Brandon@icodeblog.com

With some good information in the comments:

Santiago Lema Says:

July 23rd, 2009 at 5:10 am

Playing a 1sec silent sound every 10-15 secs does work. The other processes will continue to run as long as this goes on . That’s how I did it in my alarm clock app ( CuteClock ). It surely eats a lot of battery (as opposed to letting the phone lock itself) but definitely much less than leaving the screen on.




UIAlertView with more than one button

Taken from the UICatalog sample code.

Ensure the header file contains the following:

Code:
@interface YourViewController : UIViewController 
Add the following in the class where the alert is needed:

Code:
- (void)alertOKCancelAction {
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
Use this delegate method to process respond to the user input:

Code:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
NSLog(@"User clicked OK");
} else {

NSLog(@"User clicked Cancel");
}
}


Reference: Stitch@iphonedevsdk.com

Followers