在我的应用程序中,我通过以下方式向每个 TableView 单元格添加 3 个 UILabel。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ShowMoreCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [self getCellContentView:CellIdentifier];
return cell;
}
- (UITableViewCell *)getCellContentView:(NSString *)cellIdentifier
{
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
cell.backgroundColor=[UIColor clearColor];
for(int j = 0; j < 3; j++)
[cell insertSubview:[items objectAtIndex:j] atIndex:j];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
这里的 items 是一个 NSMutableArray
,它有 UILabel 的元素。我试图在每个 cell
中添加三个 labels
。但它只在最后一行显示 3 个 标签
。
我是不是做错了什么?
谢谢
最佳答案
您正在尝试将相同的 UILabel
对象添加到不同的单元格。 UIViews
(UITableViewCell
是其子类)只能有一个父 View 。您应该为每个单元格创建 3 个新标签(如果它还不包含它们的话)。
关于iphone - 将 NSArray 项添加到 UITableViewCell 内容 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16666421/