Why does this TableView code work?
Posted
by nevan
on Stack Overflow
See other posts from Stack Overflow
or by nevan
Published on 2010-05-03T17:07:17Z
Indexed on
2010/05/03
17:18 UTC
Read the original article
Hit count: 237
I made a typo when creating a UITableViewCell
with this code:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [self.tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"Creating cell");
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewStylePlain
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"Hello";
return cell;
}
The typo is in using UITableViewStylePlain
instead of UITableViewCellStyleDefault
. The code worked fine, creating new cells. Why?
© Stack Overflow or respective owner