I can’t get why my app crashes. Here is the code:
-(void)viewDidLoad
{
[super viewDidLoad];
self.tableContent = [NSArray arrayWithObjects:@"Blue", @"Yellow", @"Green", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableContent count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return [self.tableContent objectAtIndex:indexPath.row];
}
Here is the error I got
-[NSCFString setTableViewStyle:]: unrecognized selector sent to instance 0x4938
Here’s the error in your
cellForRowAtIndexPath:tableContentis an array ofNSStrings, so you’re returning anNSStringinstead of an object of typeUITableViewCell. So instead write:It is the
NSStringyou’ve returned in place of theUITableViewCellthat causes the error…If you want to see the text you’re sending, you’ll need to set the textlabel’s text: