2014-01-13 1 views
0

누구든지 아래에서 아이디어가 있습니까? 이 오류는 아래쪽의 행 6 & 8 번에서 발생합니다. 라벨을 합성했습니다. 건배.오류 : 'label1'속성이 'UITableViewCell'유형의 개체에서 발견되지 않았습니다.

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

사용 : 대신

- (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 stringWithFormat:p.no ]; 

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


return cell; 
} 
+0

'if (cell == nil)'블록 안에 셀당 한 번만 추가 레이블을 추가해야합니다. – rmaddy

답변

0

label1.text = [NSString stringWithFormat:p.no ]; 
label2.text = [NSString stringWithFormat: p.name ]; 

당신은 서브 뷰로 추가하지만 셀의 속성이 없습니다. 그런 식으로 캡슐화하려면 UITableViewCell을 확장 할 사용자 지정 클래스를 만들고이 방법으로 사용할 수있는 것보다 만듭니다.

+0

대단히 고마워! – shennis90

관련 문제