2012-02-27 2 views
1

나는 정적 셀을 만들고 다른 세 종류의 셀에 세 가지를 추가했습니다. UITableViewController이 있습니다.UITableVIewController 스토리 보딩 모드 정적 셀에서 일부 셀을 재사용하는 방법

첫 번째 셀 세부 사항의 일종, 마지막 셀 인 - 턴 센터 세포을 보여 얻는다 사용자 입력을 할 수 있습니다.

enter image description here

나는 중앙 셀을 재사용하고 사용자가 마지막 코멘트 상자에 들어가는 새로운 것을 추가 할.

내 정적 인 정적 셀 때문에 혼자서 중심 셀을 재사용 할 수 없기 때문에 문제가되는 것입니다. 어떻게 해결할 수 있을까요? 도와주세요.

답변

3

정적 셀을 사용하지 마십시오. 정적 셀은 재사용되지 않습니다. 정적 셀을 사용하면 xib에서만 표를 만들 수 있습니다.

세 가지 프로토 타입 셀을 만들고 다른 재사용 식별자를 지정하고 일반 셀처럼 사용하십시오.

테이블이 섹션으로 나누어지기 때문에 올바른 셀을 반환하기 위해 indexPath의 섹션 정보 만 사용하십시오. 이 같은

뭔가 작업을해야합니다 :

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 3; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section == 1) { 
     return _objects.count; 
    } 
    return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = nil; 
    if (indexPath.section == 1) { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"SecondCell"]; 
     // configure the mid cells 
     NSDate *object = [_objects objectAtIndex:indexPath.row]; 
     cell.textLabel.text = [object description]; 
    } 
    if (indexPath.section == 0) { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"FirstCell"]; 
     // configure first cell 
    } 
    else if (indexPath.section == 2) { 
     cell = [tableView dequeueReusableCellWithIdentifier:@"ThirdCell"]; 
     // configure last cell 
    } 
    return cell; 
} 

너무 tableFooterViewtableHeaderView 특성을 살펴 있습니다. 첫 번째 항목과 마지막 항목에는 셀이 필요하지 않을 수도 있습니다.

+0

테스트 해 보니 매력적이었습니다. 프로토 타입에 여러 식별자를 사용하는 지식이 부족했습니다. – carbonr

관련 문제