Skip to content

Instantly share code, notes, and snippets.

@Lordnibbler
Created March 21, 2012 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lordnibbler/2143554 to your computer and use it in GitHub Desktop.
Save Lordnibbler/2143554 to your computer and use it in GitHub Desktop.
- (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