所以我试图从 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/