UITableViewCell 设置文字

问题描述 投票:0回答:4

我正在创建示例 hello world 应用程序。代码如下。我怎样才能删除

c[cell setText:@"Hello World"] 发出警告;在下面的代码中,因为它已弃用。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[cell setText:@"Hello World"];
iphone
4个回答
25
投票

设置单元格标签文本

cell.textLabel.text = @"Hello World";

和详细标签文本

cell.detailTextLabel.text = @"yourText";

3
投票

还有更多 Objective-C 方法可以做到这一点:

[[cell textLabel] setText:@"Hello World"];

和详细标签文字:

[[cell detailTextLabel] setText:@"Hello World"];

3
投票

在 Swift 3.0 中应该是

 cell.textLabel?.text = "Hello World"

0
投票

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
}
© www.soinside.com 2019 - 2024. All rights reserved.