2013-09-06 2 views
1

빠른 질문. Prototype 셀에 다른 셀을 추가하려고합니다. 나는 "cell.textLabel.text = person.firstname;"줄을 추가했다. 그러나 세포에서 아무것도 얻지 마십시오. 누군가 도와 줄 수 있어요.동적보기 셀에 다른 자막 추가

감사

당신이 뜻하는 일
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"Persons Cell"; 

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

    // Configure the cell... 


    Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    NSString *fullname = [NSString stringWithFormat:@"%@, %@", person.surname, person.firstname]; 
    cell.textLabel.text = fullname; 
    cell.detailTextLabel.text = person.inEvent.name; 
    cell.textLabel.text = person.firstname; 
    return cell; 
} 

답변

0

"프로토 타입 셀에서 다른 셀을 추가 할 수 있습니다." ? 내 생각에 코드에 기반하여 원하는 코드를 추가하려면 코드에 UILabel을 추가하십시오. 기본값이 UITableViewCell 인 경우 textLabeldetailTextLabel의 두 개만 있습니다. 하나 더 원한다면 자신을 만들어야합니다.

동일한 레이블을 두 번 설정하는 것에 유의하십시오.

cell.textLabel.text = fullname; //setting first time 
cell.detailTextLabel.text = person.inEvent.name; 
cell.textLabel.text = person.firstname; //setting second time. This will set a new text to 'textLabel', losing its previous content (fullname) 

당신은 새로운 하나를 할당하고 cellForRowAtIndexPath: 내부 셀의있는 contentView의 하위 뷰를 같이 추가 할 수 있습니다. 그러나 실제로는 UITableViewCell의 하위 클래스를 만들고 인터페이스 빌더를 사용하여 원하는대로 레이블을 배치하고 IBOutlets을 만들고 cellForRowAtIndexPath:에 텍스트를 설정하는 것이 좋습니다.