2013-10-11 3 views
0

UITableView가있는 위의 UITableView가있는 UIViewController가 하나 있습니다. UISegmentControl이 있습니다. 세그먼트 컨트롤을 누르면 UItableCustomeCell을로드하고 싶습니다.이 구현에서 도움을 받으시겠습니까? 나는 다른 사용자 정의 전지 여기각 UISegmentController마다 다른 사용자 정의 셀 호출

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

{ 

if (indexPath.row == self.segmentedControl.selectedSegmentIndex == Test1) { 
    MytestsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MytestsCell"]; 
    if (!cell) { 
     cell = [[MyBooksCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:@"MytestsCell"]; 
    } 

    return cell; 
} 
else if (indexPath.row == self.segmentedControl.selectedSegmentIndex == tests) { 
    testCell *cell = [tableView dequeueReusableCellWithIdentifier:@"testCell"]; 
    if (!cell) { 
     cell = [[TestsCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:@"testsCell"]; 
    } 

    return cell; 
} 
break; 
case 1: 
if (indexPath.row == self.segmentedControl.selectedSegmentIndex == PTest) { 
    PTestsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PTestsCell"]; 
    if (!cell) { 
     cell = [[PTestsCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier:@"PTestsCell"]; 
    } 

    return cell; 
} 
break; 

} 

내가 한 테이블에서 그들의 3를 갖고 싶어하지 않는 코드는 3 가지고 있기 때문에 내가 cellForRowAtIndexPath에 추가하는 방법을 알고, 각 사용자 정의 셀입니다 하나의 세그먼트 컨트롤

미리 감사드립니다!

답변

0

내가 생각할 수있는 한 가지 대안은 테이블 뷰 데이터 소스를 전환하는 것입니다. 그러나 나는 그것을 추천하지 않을 것이다. 데이터 소스의 델리게이트를 정의하고 선택한 세그먼트 컨트롤의 테이블 뷰 셀을 요청할 수 있습니다. 그러나 이것은 단지 문제를 움직입니다. 나는 너의 접근 방식을 고수 할 것이다.

0

그래서 ... 여기 내가하는 일이 있습니다. 당신은 당신은 다시 한 식별자가 존재하는 세포를 얻기 위해 보장

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath 

를 사용하는 경우 iOS6의 시작, 당신은 더 이상 셀 전무가있는 tableview에서 대기열에서 제외 후 있는지 확인 할 필요가 없습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *identifier = [NSString stringWithFormat:@"%d", self.segmentedControl.selectedSegmentIndex]; 
    return [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath]; 
} 

편집 :이 같은 일을해야 있도록 추가 구성을 할 필요가 같이 또한, 보이지 않는 내가 위해 세그먼트에 해당하는이 사용 번호를 사용하는 것을 추가하는 것을 잊었다 각 셀의 식별자로 사용합니다.

+0

답장을 보내 주셔서 감사합니다.이 메소드에는 무엇을 작성해야합니까? - (id) dequeueReusableCellWithIdentifier : (NSString *) 식별자 forIndexPath : (NSIndexPath *) indexPath –

+0

아무 것도 할 필요가 없습니다. iOS 6의 UITableView 클래스에 추가 된 메서드입니다. 응답을 보면, 새로운 dequeue 메소드를 사용하여 식별자 문자열을 사용하여 tableview에서 셀을 가져온 다음 반환하는 것을 볼 수 있습니다. – JonahGabriel

관련 문제