有一个 UITableViewCell “postCell”,它是一个 IBOutlet,并附加到我放置在我的 .xib 中的单元格上。设置文本标签:
- (void)viewDidAppear:(BOOL)animated
{
postCell.textLabel.text = @"TEXT";
}
什么都没有出现。
编辑:此单元格不是表格视图的一部分。我看到的每一个答案都是假设它是。这是一个单一的 UITableViewCell。
有一个 UITableViewCell “postCell”,它是一个 IBOutlet,并附加到我放置在我的 .xib 中的单元格上。设置文本标签:
- (void)viewDidAppear:(BOOL)animated
{
postCell.textLabel.text = @"TEXT";
}
什么都没有出现。
编辑:此单元格不是表格视图的一部分。我看到的每一个答案都是假设它是。这是一个单一的 UITableViewCell。
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
PostCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PostCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"text";
return cell;
}
您可以在 cellForRowAtIndexPath 方法中为单元格设置文本标签,请参见下面的示例。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = @"Cell Title";
return cell;
}
您需要实现一些委托方法。这里有两个最重要的
tableView:cellForRowAtIndexPath:
tableView:numberOfRowsInSection:
这是有关如何实现表格视图的完整教程。