I’m wondering if there is any difference between these two approaches of setting properties on a UITableViewCell.
Option A:
In your storyboard file, on your UITableViewCell, drag your UIElements onto the UITableViewCell, tag each UIelement. Then in:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReuseableCellIdentifier:@"MyCell"];
UILabel *aLabel = [cell viewWithTag:TAG_FROM_IB];
aLabel.text = @"my text";
UIImageView *aImageView = [cell viewWithTag:TAG_FROM_IB];
aImageView.image = [UIImage imageNamed:@"myImage.png"];
return cell;
}
option B:
Drag the UIElements onto the UITableViewCell in the storyboard. Create a custom subclass of UITableViewCell, change the class of the UITableViewCell to your new custom subclass, access the properties by:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableViewCell *cell = [tableView dequeueReuseableCellIdentifier:@"MyTableViewCell"];
cell.aLabel.text = @"my text";
cell.aImageView.image = [UIImage imageNamed:@"myImage.png"];
return cell;
}
I was just wondering if there was a “preferred” or “better” way to create custom UITableViewCells. Thanks!
definitly no. two!
it much more concise: cleaner and clearer to use then! performance wise it is also superior BUT thats not a measurable amount…
+(IMHO) performance should never be the initial reason for a design decision.