Daryl Spitzer
Daryl Spitzer

Reputation: 149494

alternative to deprecated UITableViewCell setText?

Code in the book Beginning iPhone Development (by Dave Mark & Jeff LaMarche) assigns to the UITableViewCell text property:

UITableViewCell *cell = ...
...
cell.text = ...

This assignment brings up a "'setText' is deprecated..." warning. What should I use as an alternative?

Also, how do I open the long URL in the warning (in Xcode) without retyping the whole thing?

Upvotes: 30

Views: 27215

Answers (6)

Ekambaram E
Ekambaram E

Reputation: 1262

cell.textLabel was deprecated

enter image description here

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else {
        return UITableViewCell()
    }
    
    var cellContext = cell.defaultContentConfiguration()
    cellContext.text = ""
    cellContext.secondaryText = ""
    cell.contentConfiguration = cellContext
    
    return cell
}

Solution --> Use UIListContentConfiguration:

enter image description here

Upvotes: 4

pableiros
pableiros

Reputation: 16042

After 12+ years Apple will deprecate textLabel:

enter image description here

Now starting with iOS 14, you will need to use UIListContentConfiguration:

Swift:

var content = cell.defaultContentConfiguration()
content.text = "text label"
content.secondaryText = "detail text"
        
cell.contentConfiguration = content

Upvotes: 15

Mark
Mark

Reputation: 6128

To address the second question.

I'm not sure what you mean by URL but to get the full text of the build output, which is where the warning bubble comes from:

1) open the build window (default key binding Command-Shift-B)

At the bottom of the build progress view there are four buttons. The buttons from left to right are a checkmark, a warning symbol, some dotted lines, and a popup menu for more options.

Make sure the third symbol, the one with the dotted lines, has a dark grey background. Toggle it if you are in doubt. The new view that is exposed when this button is pressed has the full text output from the build process (compiler, linker, shell script output, etc...)

I believe this is what you are asking about.

You can use the Command-= and Command-Shift-+ to move through the warnings and errors. When you do this the full text of each warning/error bubble will be selected in the full output view.!

Upvotes: 1

Yash Kaushik
Yash Kaushik

Reputation: 61

you Use This Code:-

"cell.textLabel.text"

Remove The Warning Of Text deprecated UITableViewCell setText?

Upvotes: 1

taus-iDeveloper
taus-iDeveloper

Reputation: 701

Deprecated suggests that you change your code to use the new method suggested by Apple. Any deprecated methods would be removed in the future update releases (for ex: they might remove it from OS 3.1) So, instead of setText, use this

 [cell.textLabel setText] method

Upvotes: 1

marcc
marcc

Reputation: 12399

try:

cell.textLabel.text = @"test";

(Ah, it's nice to be answer 3.0 SDK questions now)

Upvotes: 74

Related Questions