iphone - 将 NSArray 项添加到 UITableViewCell 内容 View

标签 iphone ios uitableview nsarray

在我的应用程序中,我通过以下方式向每个 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/

相关文章:

ios - swift 将从@escaping 接收到的值分配给另一个类中的实例变量

javascript - JS - 获取当前网站名称(类似于 Safari)

ios - 如何获得比 1Hz 更快的 CoreLocation 刷新率?

iphone - 如何在 Android 和 iOS 之间进行代码共享

iphone - 通过点符号访问 NSDictionary?

ios - 在ios中将json转换成字典

ios - 相机 View 在 Swift 中旋转 90 度

ios - Xcode 调试内存图不显示对象/边缘名称

objective-c - 滚动 UITableView 时单元格数据显示不正确

ios - 有视频 : After Peek and Pop (3D Touch) background keeps scrolling