Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone/iPad SimpleTableViewCells: What replaces the deprecated setImage setText on table cells?

iPhone/iPad SimpleTableViewCells: What replaces the deprecated setImage setText on table cells?

The below code gives warnings that setImage and setText are deprecated. So what replaced them? What is the new better way to get this simple behavior?

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
       reuseIdentifier: SimpleTableIdentifier] autorelease];
}
cell.image=[UIImage imageNamed:@"Wazoo.png"];;
cell.text = @"Wazoo";

So what is the simplest way to have the same affect as image/text of a cell without doing a lot of work or getting warnings?

like image 497
MikeN Avatar asked Sep 18 '10 19:09

MikeN


2 Answers

With new release of iOS SDK, setText and setImage properties are deprecated and they are replaced by textLabel.text for setText and imageView.image for setImage...
With this new properties, your code would be:

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
       reuseIdentifier: SimpleTableIdentifier] autorelease];
}
cell.imageView.image = [UIImage imageNamed:@"Wazoo.png"];;
cell.textLabel.text = @"Wazoo";

This properties are usually used when the cell uses preimpostated styles like UITableViewCellStyleDefault, UITableViewCellStyleSubtitle, UITableViewCellStyleValue1 and UITableViewCellStyleValue2 or CGRect...
If you will display also a subtitle, the code to be used is:

cell.detailTextLabel.text = @"Your Subtitle Here!";
like image 165
matteodv Avatar answered Oct 22 '22 04:10

matteodv


You call textLabel.text and imageView.image on the cell.

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];

if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
       reuseIdentifier: SimpleTableIdentifier] autorelease];
}
cell.imageView.image=[UIImage imageNamed:@"Wazoo.png"];;
cell.textLabel.text = @"Wazoo";
like image 28
Convolution Avatar answered Oct 22 '22 02:10

Convolution