Xcode - 更改UITableViewCell上的标签数据
问题描述:
我有一个TableView
,我用自定义单元格填充。在这段代码中,我想将数据设置在不同的标签上,但它似乎不起作用。我不能添加任何网点,不知道为什么我不能这样做。当我尝试使用cell.textLabel.text = @"Data";
更改数据时,它似乎添加了一个新标签,而不是更改当前标签的文本。Xcode - 更改UITableViewCell上的标签数据
我该怎么办?下面的代码显示了我如何填充列表。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SenasteTableCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"SenasteTableCell" owner:nil options:nil];
for (UIView *view in views)
{
cell = (SenasteTableCell*)view;
}
}
return cell;
}
答
您应该可以创建网点。如果您正在使用自定义表格视图单元格(假设SenasteTableCell是Im),请确保在界面生成器中单击单元格并将其类设置为SenasteTableCell。此时,您应该能够控制从标签拖动到文件并创建网点。
答
设置一个唯一的标签在customcell标签,你可以得到它的实例作为
UILabel *Label=(UILabel *)[cell viewWithTag:2];//2 is th unique tag value i set in the cell for that label
您可以在细胞获得每个视图对象的值,这样
如
UIButton *sampleButton=(UIButton *)[cell viewWithTag:4];
答
我想你还没有设置FileOwner
属性表单XIB
文件。 set fileowner
as UITableViewClass
and UITableViewCell
As SenasteTableCell
。 要连接网点,您必须首先选择SenasteTableCell
,并且会有一个网点列表。