boom
boom

Reputation: 6166

UITableViewCell setting text

I am creating sample hello world application. The code is below. How can i removed the

warning at c[cell setText:@"Hello World"]; in the code below as it deprecated.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[cell setText:@"Hello World"];

Upvotes: 12

Views: 19910

Answers (4)

fegoulart
fegoulart

Reputation: 2037

UITableViewCell textLabel is deprecated now.

iOS 15+ should use:

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
}

Upvotes: 0

Ash
Ash

Reputation: 5712

In Swift 3.0 its should be

 cell.textLabel?.text = "Hello World"

Upvotes: 3

timmartins
timmartins

Reputation: 49

There's also more Objective-C way of doing that:

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

and detail label text:

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

Upvotes: 3

Gyani
Gyani

Reputation: 2241

set cell label text

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

and detail label text

cell.detailTextLabel.text = @"yourText";

Upvotes: 25

Related Questions