Created
March 13, 2014 01:52
-
-
Save keicoder/9520568 to your computer and use it in GitHub Desktop.
objective-c : two ways of making UITableView Cell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//two ways of making UITableView Cell | |
//ex | |
//1. much simpler | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
static NSString *CellIdentifier = @"Cell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
// Configure the cell... | |
Note *note = [self.fetchedResultsController objectAtIndexPath:indexPath]; | |
cell.textLabel.text = note.noteTitle; | |
return cell; | |
} | |
//2. or this way | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
static NSString *CellIdentifier = @"Cell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; | |
} | |
// Configure the cell... | |
Note *note = [self.fetchedResultsController objectAtIndexPath:indexPath]; | |
cell.textLabel.text = note.noteTitle; | |
return cell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment