我想知道这两种在UITableViewCell.
选项 A:在您的故事板文件中,在您的 s 上UITableViewCell,将您UIElement的 s 拖到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:将UIElements 拖到UITableViewCell情节提要中的 s 上。创建 的自定义子类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的方式来创建 custom 。谢谢!