使用NSCoder时,在UITableview中的何处添加自定义tableview单元格标签?

使用NSCoder时,在UITableview中的何处添加自定义tableview单元格标签?,uitableview,xcode4.5,nscoder,Uitableview,Xcode4.5,Nscoder,使用NSCoder时,在UITableview中的何处添加自定义tableview单元格标签? 我已经创建了UITableViewCell类,并在interface builder中连接了所有内容 我试图替换cell.textlab.text=oneName.name;使用cell.label.text=oneName.name它只显示了一个黑色正方形 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt

使用NSCoder时,在UITableview中的何处添加自定义tableview单元格标签? 我已经创建了UITableViewCell类,并在interface builder中连接了所有内容

我试图替换cell.textlab.text=oneName.name;使用
cell.label.text=oneName.name它只显示了一个黑色正方形

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (!cell) {
        cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    // Configure the cell...
    NSUInteger row = [indexPath row];
    DrillObject *oneName = [self.addDrill objectAtIndex:row];
    cell.textLabel.text = oneName.name;



    return cell;
}

你确定你的标签大小合适吗?当使用自定义单元格时,我真的建议使用免费的Sensive TableView框架。框架会自动将对象的数据加载到自定义标签中,并在需要时自动调整标签/单元格的大小。

有两个选项可将标签添加到自定义单元格类,如您所需:
1-将标签添加到xib文件中的单元格中,并为其指定标记,然后创建一个getter,如下所示:

-(UILabel*)label
{
     id label = [self viewByTag:3]; 
     if([label isKindOfClass:[UILabel class]])
     {
             return label;
     }
     return nil;
}
UILabel *label = [UILabel alloc] initWithFrame:myFreame];
[label setBackgroundColor:[UIColor clearColor]];

// now you should have property on .h file like this 
@property (nonatomic, weak) UILabel *label;
// so back to the init dont forget to do this

_label = label;
2-在init方法中创建标签,不要忘记将标签背景颜色设置为透明颜色,如下所示:

-(UILabel*)label
{
     id label = [self viewByTag:3]; 
     if([label isKindOfClass:[UILabel class]])
     {
             return label;
     }
     return nil;
}
UILabel *label = [UILabel alloc] initWithFrame:myFreame];
[label setBackgroundColor:[UIColor clearColor]];

// now you should have property on .h file like this 
@property (nonatomic, weak) UILabel *label;
// so back to the init dont forget to do this

_label = label;

就是这样。

你说的“使用NSCoder时”是什么意思?我之所以这么说,是因为通常的实现方法无法使用cell.label.text=[addDrill objectAtIndex:indexPath.row];对于第一个问题,如果我使用故事板也是一样的,因为它为
self.view提供了一个错误?如果您在CustomCell类中执行此操作,则只需执行此[self-viewByTag:3],而无需查看。