Created
March 21, 2012 01:47
-
-
Save Lordnibbler/2143554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
if (editingStyle == UITableViewCellEditingStyleDelete) { | |
// Delete the row from the data source | |
Channel *channelToDestroy = [channels objectAtIndex:indexPath.row]; | |
[self destroyChannelWithId:channelToDestroy.identifier]; | |
[super.channels removeObject:channelToDestroy]; | |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
} | |
else if (editingStyle == UITableViewCellEditingStyleInsert) { | |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | |
} | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
// build the custom cell from prototype "ChannelItemViewCell" | |
static NSString *CellIdentifier = @"ChannelItemViewCell"; | |
ChannelItemViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[ChannelItemViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; | |
} | |
// grab the channel to display on this iteration through the tableview | |
Channel *channel = [channels objectAtIndex:indexPath.row]; | |
// set the labels on the cell | |
cell.channelName.text = channel.name; | |
if(channel.numOfListeners == [NSNumber numberWithInt:1]) { | |
cell.numberOfListeners.text = [NSString stringWithFormat:@"1 Listener"]; | |
} else { | |
cell.numberOfListeners.text = [NSString stringWithFormat:@"%u Listeners", [channel.numOfListeners intValue]]; | |
} | |
return cell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment