shweta thakar
shweta thakar

Reputation: 1757

iphone:Error while setting the text in table row cell in xcode 4.2

when i use this code it shows an error

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] ;
}

// Set up the cell
SQLiteTutorialAppDelegate *appDelegate = (SQLiteTutorialAppDelegate *)[[UIApplication sharedApplication] delegate];
Animal *animal = (Animal *)[appDelegate.animals objectAtIndex:indexPath.row];

[cell setText:animal.name];
return cell;

}

when i use [cell setText:animal.name] it shows an error like 'setText' is deprecated.

Upvotes: 0

Views: 846

Answers (3)

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

Use [cell.textLabel setText:animal.name];

Upvotes: 2

GarlicFries
GarlicFries

Reputation: 8323

That's because the UITableViewCell text property was deprecated as of iOS 3.0--see the reference here. The UILabel that is used for the text label is exposed as the textLabel property of a UITableView instance. Try this instead:

cell.textLabel.text = animal.name;

Upvotes: 1

alloc_iNit
alloc_iNit

Reputation: 5183

Yeah..use the following line instead..

    [cell.textLabel setText:(NSString *)]

Upvotes: 1

Related Questions