2010-02-16 131 views

回答

1

创建扩展的UITableViewCell

@interface CustomTblCell : UITableViewCell 

的自定义类在对应NIB CustomTblCell.xib拖放的UILabel和UIButton的元件(并排侧)。

最后,在你的方法-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath初始化并返回CustomTblCell

希望这有助于!

这里是我上面

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *CustomCellIdentifier = @"customCellIndentifier"; 

    CustomTblCell *cell = (CustomTblCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; 
    if(cell == nil){ 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTblCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.label.text = @"My Product"; 
    return cell; 
} 

如果你有很多行你的台,使得用户通过该表使用“dequeueReusableCellWithIdentifier`滚动提到cellForRowAtIndexPath:方法的代码段。这优化了代码以重用现在不在用户视图中的同一个customTblCell对象。 deque方法将一个String作为输入参数(customTableCellIdentifier)。确保它与您在创建CustomTblCell时在IB中指定的标识符字符串相匹配

+0

谢谢。这样可行。我的实际解决方案是用这个笔尖加载视图控制器:一行而不是两行似乎更优雅。 – Jacko 2010-02-20 03:01:43

相关问题