any performance difference or better code reuse between tagging a UIElement or subclassing a control?

StackOverflow https://stackoverflow.com/questions/13592464

  •  02-12-2021
  •  | 
  •  

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top