ios - ILTableViewCell/UITableViewCell 生命周期

标签 ios objective-c uitableview

所以我试图从 UITableView 的实例重命名 UITableViewCell 类的实例中的 UILabel,但是,那时 UILabel 没有加载,所以当我在调试器中打印它时,它是零。

因此,我在 UITableViewCell 中创建了一个 NSString 并设置了它,它的行为符合预期,因为调试器按照我设置的方式打印出来。

现在我的问题是我应该在生命周期中的什么地方设置 UILabel 和我成功设置的 NSString

-(void) layoutSubviews
{
    [super layoutSubviews];
    self.fileLabel.text = self.fileName;
    NSLog(@"filelabel.text: %@", self.fileLabel.text);
}

layoutSubviews 不工作我应该使用任何其他方法吗?

最佳答案

如果我理解您的问题 - 您正在尝试向 UITableViewCell 的子类添加标签,如果是这样,请使用 cellForRowAtIndexPath 方法,例如 -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    YourCell *urCell = (YourCell *)cell;
    // Configure the cell...

   urCell.fileLabel.text = @"Some text";

    return cell;
}

关于ios - ILTableViewCell/UITableViewCell 生命周期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102163/

相关文章:

iphone - 在 UIScrollView 上检测用户触摸

iphone - 如何直接从上一个 View 导航回第一个 View

uitableview - 所有 uitableviewcells 在 iOS 9 上变成一行

ios - indexPath.row 在 tableView 自定义单元格 iOS 中没有给出正确的值

ios - UITableView 多选的选定复选标记未保持选中状态

iOS:LLDB 多行断点命令无法按预期工作

C# vuforia.image.pixels 覆盖到 iOS CIImage 或 CGImage

objective-c - Objective-c 中的 pHash(图像哈希)不起作用

iphone - 从 View 1 切换到蓝牙设置......不可能吗?

ios - 有没有办法使用私有(private) API 在 iOS 10+ 中获取 iPhone 充电器的信息?