iOS 6 Table View crashes when deployed to iOS 5

Apple have changed the UITableViewController template in iOS 6 a bit. Specifically, when you create a new UITableViewController class, it’s created using something like this (in the cellForRowAtIndexPath method): – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @”Cell”; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; // Configure the cell… return cell; } When […]

How to create an Action Sheet and respond to it

This will bring up the UIActionSheet on iPhone devices from the bottom of the screen: // trigger a UIActionSheet UIActionSheet *myActionSheet; myActionSheet = [[UIActionSheet alloc]initWithTitle:@”My Title” delegate:self cancelButtonTitle:@”Cancel” destructiveButtonTitle:@”Cancel in Red” otherButtonTitles:@”Open in Safari”, nil]; myActionSheet.actionSheetStyle = UIActionSheetStyleAutomatic; [myActionSheet showInView:self.view]; You can add more buttons if you like by comma separating them. If you don’t […]

How to change a cell’s selection colour

By default, when you touch a cell in a UITableView, it lights up bright blue. You can use this property to change the cell’s selection style in the cellForRowAtIndexPath method: cell.selectionStyle = UITableViewCellSelectionStyleGray; Possible values are UITableViewCellSelectionStyleGray UITableViewCellSelectionStyleBlue (the default) UITableViewCellSelectionStyleNone Alternatively you can select the cell in Interface Builder and pick these values from […]

How to open a URL in Safari programmatically

Instead of loading a URL into a UIWebView we can also launch Safari to display it: UIApplication *mySafari = [UIApplication sharedApplication]; NSURL *myURL = [[NSURL alloc]initWithString:@”http://www.mydomain.com”; [mySafari openURL:myURL]; The method returns a BOOL value which will feed back if this operation was a success or not: if (![mySafari openURL:myURL]) { // opening didn’t work } […]

How to use iCloud key value storage

Storing small bits of info in iCloud is very similar to using the local NSUserDefaults device storage. The only difference is that your App ID needs to be enabled for iCloud in iTunes Connect and that you need to enable it in your project: Here’s how you save data to iCloud (from a text label): […]