iOS Snippets

A collection of useful iOS snippets

Open a link from a UITableViewCell, using the cell content as a URL parameter

view plain print about
1- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
2 NSString* thisValue = [[[self.tableView cellForRowAtIndexPath:indexPath] textLabel] text];
3
4 NSString* thisURL = [NSString stringWithFormat:@"http://www.site.co.uk?&param=%@", thisValue
5 ];
6
7 [[UIApplication sharedApplication] openURL:[NSURL URLWithString: thisURL]];
8}

Run code in the background

view plain print about
1dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT), 0), ^{
2 // perform some intense heavy function
3
4 // update UI etc - do something while the background thread is running
5 dispatch_async( dispatch_get_main_queue(), ^{
6 // update progress bar type thing
7 });
8});