2012-11-27 22 views
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。谢谢!

回答

0

definitly no。二!

它更简洁:使用起来更干净,更清晰!性能明智这也是优越的,但那不是一个可测量的数量...

+(恕我直言)性能不应该是最初的原因的设计决定。

相关问题