iPhone/iPad SimpleTableViewCells: What replaces the deprecated setImage setText on table cells?
iPhone/iPad SimpleTableViewCells: What replaces the deprecat开发者_JAVA技巧ed 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?
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!";
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";
精彩评论