Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Szabolcs Varga
Szabolcs Varga
Courses Plus Student 662 Points

UITableViewController Class Problem

Hi, i'm doing the self destruction app, and have some problems. If i make a class which is the subclass of an UITableViewController, the cell options are always commented out and this lines are missing:

static NSString *CellIdentifier = @"Cell"; 
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

But in the video when Ben makes totally the same it shows up as sample code and he don't have to type it manually. Do you have any idea what makes this? Thanks

2 Answers

Matthew Mascioni
Matthew Mascioni
20,444 Points

Which version of Xcode are you using? When you create a subclass in Xcode, some of the boilerplate code is commented out or omitted, and this changes between major versions sometimes. You will need to implement the didSelectRowAtIndexPath: delegate method as well as making sure your cell reuse identifier is the same as the one you specify in your storyboard.

Szabolcs Varga
Szabolcs Varga
Courses Plus Student 662 Points

I'm using the newest version. I have the same sample codes that Ben has in the video, except the two lines from my first post, but for me a lot of stuff is commented out and they are in a different sequence.

It looks like this: /*

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];

    // Configure the cell...

    return cell; } */

/* // Override to support conditional editing of the table view.

  • (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */

/* // Override to support editing the table view.

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:@[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 }
    } */

/* // Override to support rearranging the table view.

  • (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */

/* // Override to support conditional rearranging of the table view.

  • (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */


pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */