0
我想知道这两种方法在UITableViewCell
上设置属性是否有任何区别。标记UIElement或子类化控件之间的任何性能差异或更好的代码重用?
选项A: 在你的故事板文件,您UITableViewCell
,拖动UIElement
小号到UITableViewCell
,标记每个UIelement
。然后在:
- (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;
}
选项B: 拖动UIElement
小号到在故事板的UITableViewCell
。创建的UITableViewCell
自定义子类,这个类的UITableViewCell
更改为新的自定义子类中,通过访问属性:
- (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;
}
我只是想知道,如果有一个“最好”或“较好”的方式来创建自定义UITableViewCell
s。谢谢!