2013-06-28 1 views
1

하나의 섹션이있는 UITableView가 있습니다. 해당 섹션의 셀에는 모두 PLContactCell이라는 UITableViewCell의 하위 클래스에서 파생 된 셀이 있습니다.DIITerent 형식 및 동작 동일한 테이블의 섹션 UITableView 셀

내가하고 싶은 것은 테이블의 마지막 행에 대해서만 PLContactCell을 사용하지 않는 것입니다. 난 그냥 포맷 할 수있는 정상적인 UITableViewCell을 사용하고 싶습니다 그러나 내가 원할 것입니다. 나는 또한이 세포가 도청당하는 것에 반응하지 않도록 할 수 있기를 바란다.

내 초기 cellForRowAtIndexPath 방법은 다음과 같습니다 그래서 내가 XIB 파일에 jQuery과 셀을 만들고 여기에 "newCell"의 재사용 식별자를 추가하려고

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

PLContactCell *cell = [tableView dequeueReusableCellWithIdentifier:[PLContactCell reuseIdentifier]]; 

    if (!cell) { 
     cell = [PLContactCell reusableCell]; 
     cell.delegate = self; 
    } 

    id modelObject = [[sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; 

    if ([modelObject isKindOfClass:[NSString class]]) { 
    [cell configureWithString:modelObject]; 
    } else { 
     [cell configureWithUser:modelObject]; 
    } 

    return cell; 
} 

편집 할 수 있습니다. 그런 다음이 코드를 추가했습니다.

if (indexPath.row == [[sections objectAtIndex:indexPath.section] count] - 1) { 
     NSString *CellIdentifier = @"newCell"; 
     noFormatCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
} 

아무 것도하지 않습니다. 내 질문은, 어떻게 섹션의 마지막 행에 액세스 할 수 있으며 어떻게 그 셀은 PLContactCell 아니라 UITableView 셀을 만들 수 있도록합니까.

+0

특정 질문이 있으십니까? –

+0

아마도'cellForRowAtIndexPath : '의 시작 부분에서 (indexPath.row + 1)을 [tableView numberOfRowInSection : indexPath.section]과 비교하여 마지막 셀에 있는지 알 수 있습니다. 그렇다면 다른 셀을 호출하십시오. 하지만 당신이 필요로하는 것 같습니다 데릭 대답을 고려하십시오. – zbMax

+0

@ TimothyMose : 제 질문은, 어떻게 섹션의 마지막 행에 액세스 할 수 있으며 어떻게 그 세포가 PLContactCell하지만 UITableView 셀되지 않도록합니다. – jac300

답변

0

언제나 끝나면 UITableView의 바닥 글보기를 사용해보십시오. 그런 다음 UITableViewDataSource에서 여분의 논리를 유지할 수 있습니다.

셀로 있어야하는 경우 마지막 섹션에 추가 행 수를 추가 한 다음 if 문 검사를 수행하여 -tableView : cellForRowAtIndexPath : 구현에서 조심하십시오. 저는 여러분이 지금부터 몇 달/몇 년 동안 무엇을하고 있었는지 알아내는 것이 더 깔끔하고 쉽게 이해할 수 있도록 푸터 방식을 시도해 보길 강력하게 권합니다.

여기에 몇 가지 코드가 있습니다. UITableView에서 그룹화 된 스타일을 사용하는 경우 다른 섹션을 만들어야합니다.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (section == sections.count - 1) //Looking for last section 
    { 
     return [sections objectAtIndex:section].count + 1; //Add one to the last section 
    } 

    return [sections objectAtIndex:section].count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSInteger row = indexPath.row; 


    if ((sections.count == indexPath.section) && [sections objectAtIndex:indexPath.section].count == indexPath.row) 
    { 
     //Here you would create and return your UITableViewCell 
    } 

PLContactCell *cell = [tableView dequeueReusableCellWithIdentifier:[PLContactCell reuseIdentifier]]; 

    if (!cell) { 
     cell = [PLContactCell reusableCell]; 
     cell.delegate = self; 
    } 

    id modelObject = [[sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; 

    if ([modelObject isKindOfClass:[NSString class]]) { 
    [cell configureWithString:modelObject]; 
    } else { 
     [cell configureWithUser:modelObject]; 
    } 

    return cell; 
} 
+1

예, 저는 바닥 글을 선호하지만 프로젝트 담당은 아니며 분명히 셀이어야합니다. 지금 당장 : if (indexPath.row == [[섹션 objectAtIndex : indexPath.section] count] - 1) { NSString * CellIdentifier = @ "newCell"; noFormatCell = [tableView dequeueReusableCellWithIdentifier : CellIdentifier]; } 그러나 이것은 아무 것도하지 않습니다. 그 셀 식별자로 펜촉에 셀을 만들었습니다. 코드를 어떻게 작성해야할지 모르겠습니다. – jac300

+0

위의 코드 중 일부입니다. – Derek

관련 문제