Label in Custom UITableView cell not allocated memory in iOS6

313 Views Asked by At

I have made a custom UITableViewCell which has elements like label and a segmentcontrol But when i try to access the elements in the cellforrowatindexpath the elements are not allocated any memory . the cell instance has been allocated memory . i have checked the xib and connected the outlets. Here is the code in the cellforrowatindexpath-

SegmentCell *cell;
[tableView registerNib:[UINib nibWithNibName:@"SegmentCell" bundle:nil] forCellReuseIdentifier:@"SegmentCell"];
[tableView registerClass:[SegmentCell class] forCellReuseIdentifier:@"SegmentCell"];
cell = (SegmentCell *)[tableView dequeueReusableCellWithIdentifier:@"SegmentCell" forIndexPath:indexPath];
cell.title.text=@"Hell*emphasized text*o";
return cell;

The title is the label which shows nil in print description

2

There are 2 best solutions below

1
Noah Witherspoon On

UITableViewCell’s title is a deprecated property of type NSString, not UILabel. Use the titleLabel property instead.

cell.titleLabel.text = @"whatever";

0
Periklis Konstantinidis On

Since title is a property of your custom class SegmentCell, you are responsible to allocate an instance of UILabel and assign it to title. If it is included in your Nib file, be sure it is bound to the class property.