shennis90 shennis90 - 1 year ago 53
iOS Question

Error: property 'label1'not found on object of type 'UITableViewCell'

Anyone got any ideas on the below? The error comes about on lines 6 & 8 from the bottom. I have synthesized the labels. Cheers.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"Cell";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];

UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 12, 240, 20)];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(250, 12, 50, 20)];

label1.text = @"Left";
label2.text = @"Right";

[cell.contentView addSubview:label1];
[cell.contentView addSubview:label2];

// Configure the cell...
President *p = (President *)[self.importedRows objectAtIndex:indexPath.row];
cell._label1.text = [NSString ];

cell._label2.text = [NSString stringWithFormat: ];

return cell;

Answer Source

Instead of:

cell._label1.text = [NSString ];
cell._label2.text = [NSString stringWithFormat: ];


label1.text = [NSString ];
label2.text = [NSString stringWithFormat: ];

You just added them as subview but there are not properties of cell. If you want to encapsulate it like that, create your custom class that will extend UITableViewCell and than you can use it this way.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download