Skip to content

Instantly share code, notes, and snippets.

@steveoleary
Forked from tmdvs/gist:2787274
Created June 27, 2012 09:39
Show Gist options
  • Save steveoleary/3002951 to your computer and use it in GitHub Desktop.
Save steveoleary/3002951 to your computer and use it in GitHub Desktop.
UITableViewCell
What Apple gives you and will cause a crash as dequeueReusableCellWithIdentifier: can't return a cell as none have ever been initialised.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
What should be there by default for the app to run (ARC version)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment