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 trialShaun Kelly
5,648 PointsCode isn't working and not showing any cells ?
TableViewController.h
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController
@property (nonatomic, strong) NSArray *titlesArray;
@end
TableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.titlesArray = [NSArray arrayWithObjects:@"Pointers in memory",@"Memory Managment",@"Learning WebDesign",@"How to create you first mobile app", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.titlesArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [self.titlesArray objectAtIndex:indexPath.row];
return cell;
}
2 Answers
X. Szuh
2,486 PointsYou need to conform to the tableviews delegate and data sorce protocols. Also do not forget to set delegate to self,
Alp Eren Can
25,230 PointsYour code seems OK. You should check for the cell reuse identifier in the storyboard. It should be same with the one in code which is "Cell" for your case.
Alp Eren Can
25,230 PointsAlp Eren Can
25,230 PointsThere is no need to conform explicitly since UITableViewController already conforms to these protocols. Implementations of the required methods are enough.