【问题标题】:UITableViewCell custom (nib)UITableViewCell 自定义(笔尖)
【发布时间】:2011-05-08 10:18:38
【问题描述】:

我已经用委托在 nib 文件中创建了一个自定义单元格。

我已经为自定义单元格定义了一个 .h 和 .m:

@interface InscriptionCustomCell : UITableViewCell {

IBOutlet UILabel *titreCell;
IBOutlet UITextField *contenuCell;

}

@property(nonatomic,retain) UILabel *titreCell; @property(nonatomic,retain) UITextField *contenuCell;

@结束

当我尝试将它与我的 tableView 一起使用时:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"InscriptionCustomCell";

InscriptionCustomCell *cell = (InscriptionCustomCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//[cell.textLabel setText:@"Cell"];
// Configure the cell...

if(indexPath.section ==0)
{
    [cell.titreCell setText:[model.listModuleInfoPerso objectAtIndex:indexPath.row]];
    [cell.contenuCell setPlaceholder:[model.listModuleInfoPerso objectAtIndex:indexPath.row]];
}else {
    [cell.titreCell setText:[model.listModuleInfoSupp objectAtIndex:indexPath.row]];
    [cell.contenuCell setPlaceholder:[model.listModuleInfoSupp objectAtIndex:indexPath.row]];
}
return cell;

}

我有一个错误:

reason: '-[UITableViewCell titreCell]: unrecognized selector sent to instance 0x4b5f430'

为什么?我的自定义单元格是自己的声明!

【问题讨论】:

    标签: iphone cell


    【解决方案1】:

    这是错误的:

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    

    您正在创建一个 UITableViewCell 实例而不是您的自定义单元格。

    【讨论】:

      【解决方案2】:
      if (cell == nil) {
          NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell"owner:self options:nil];
          cell = [nib objectAtIndex:0];
      }    
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多