使用NSCoder时,我在UITableview中添加自定义tableview单元格标签的位置? 我已经创建了UITableViewCell类并在界面构建器中将所有内容挂钩。
我尝试替换cell.textLabel.text = oneName.name; with
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;
}
答案 0 :(得分:0)
您确定您的标签尺寸合适吗?使用自定义单元格时,我真的建议使用免费的Sensible TableView框架。框架会自动将对象的数据加载到自定义标签中,并且还会在需要时自动调整标签/单元格的大小。
答案 1 :(得分:0)
有两个选项可以在此处为您的CustomCell类添加标签:
1-在xib文件中为您的单元格添加一个标签并为其指定一个标签,然后创建一个这样的getter:
-(UILabel*)label
{
id label = [self viewByTag:3];
if([label isKindOfClass:[UILabel class]])
{
return label;
}
return nil;
}
2-在init方法中创建标签,不要忘记将标签背景颜色设置为清除颜色,如下所示:
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;
多数民众赞成。