我正在创建示例 hello world 应用程序。代码如下。我怎样才能删除
c[cell setText:@"Hello World"] 发出警告;在下面的代码中,因为它已弃用。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell setText:@"Hello World"];
设置单元格标签文本
cell.textLabel.text = @"Hello World";
和详细标签文本
cell.detailTextLabel.text = @"yourText";
还有更多 Objective-C 方法可以做到这一点:
[[cell textLabel] setText:@"Hello World"];
和详细标签文字:
[[cell detailTextLabel] setText:@"Hello World"];
在 Swift 3.0 中应该是
cell.textLabel?.text = "Hello World"
UITableViwCell 现已弃用。
iOS 15+ 应使用:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "acme")
var content = cell.defaultContentConfiguration()
content.text = "Hello World"
cell.contentConfiguration = content
return cell
}