我是IOS开发的新手。如何设置detailTextLabel的文本,在第二行使用Swift?
我需要这样的东西,但是对于具体的detailTextLabel:
cell.detailTextLabel?.text = "Text"
答案 0 :(得分:0)
我知道,您的问题是您不知道如何更改UITableView
中每个单元格的文本 - 您当前的方法显然是为每个单元格设置相同的文本。
您需要的是一个包含不同文本的数组,允许您在每个单元格中添加不同的文本字符串。以下是如何在Objective-C
在标题(.h)文件中声明一个数组,如下所示:
NSArray *detailArray;
在您的实现(.m)文件中,使用viewDidLoad
方法填充数组,如下所示:
// Make an array and populate it.
detailArray = @[@"text one", @"text two", nil]; // etc....
在detailTextLabel
委托方法中设置UITableView
时,请执行以下操作以从存储在数组中的字符串设置文本标签:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", detailArray[indexPath.row]];