2013-07-10 4 views
0

이것은 매우 특이합니다. UITableViewDelegate 및 UITableViewDatasource 메서드를 구현하는 UIViewController가 있습니다. 대리자 및 데이터 소스 속성을 첨부하고 로그를 통해 호출되고 있는지 확인했습니다.UITableViewCell 삭제 관련 문제

내 테이블이 셀 프로토 타입 셀을 사용하고 있으며 두 개의 섹션이 있으며 섹션 헤더를 사용하고 있습니다.

셀 삭제 (셀을 가로로 스 와이프 한 다음 삭제 버튼이 표시됨)를 제외하고 내 테이블이 잘 작동합니다. 그들은 필요한 모든 셀, 섹션 헤더, 사용자 정의 셀 등을 올바르게 표시하고 있습니다. 삭제 버튼이 표시되지 않습니다. 내 로그에서 editingStypeForRowAtIndexPath 및 canEditRowAtIndexPath가 호출되는 것을 볼 수 있지만 삭제 버튼이 나타나지 않습니다.

그러나 cellForRowAtIndexPath를 편집하여 내 하위 클래스 대신 표준 UITableViewCells를 반환하면 삭제 단추가 나타납니다. 이것에 대해 UITableViewSubclass가 무엇을 지원해야합니까? 과거에는 비슷한 코드 작업이 필요 없었습니다.

내 UITableViewCell 하위 클래스를 살펴보십시오. 몇 가지 텍스트 레이블, 이미지보기 및 단추가 배경 이미지 위에 놓여 있습니다. 평범하지 않은 것은 아무것도 없다.

모든 제안을 환영

가 여기 내 TV 코드 :

#pragma mark UITableViewDataSource 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    if(section == kInvitesReceivedSection){ 
     return self.invitesReceived.count; 
    } 
    else if(section == kInvitesSentSection){ 
     return self.invitesSent.count; 
    } 
    return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if(indexPath.section == kInvitesReceivedSection){ 
     SMInviteReceivedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMInviteReceivedTableViewCell"]; 
     cell.invite = self.invitesReceived[indexPath.row]; 
     cell.delegate = self; 
     return cell; 
    } 
    else if(indexPath.section == kInvitesSentSection){ 
     SMInviteSentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMInviteSentTableViewCell"]; 
     cell.invite = self.invitesSent[indexPath.row]; 
     cell.delegate = self; 
     return cell; 
    } 

// Swap out for these and the delete button will appear 
//  UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
//  cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; 
//  return [[UITableViewCell alloc]init]; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

    // programmatcially generate UIViews 
    ... 
    return headerView; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 

    if(section == 0 && self.invitesReceived.count == 0){ 
     return 0; 
    } 
    else if(section == 1 && self.invitesSent.count == 0){ 
     return 0; 
    } 
    return 44; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); 
     return UITableViewCellEditingStyleDelete; 

} 

// This is called when the user swipes across a cell and presses delete. 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); 
    if(indexPath.section == kInvitesReceivedSection){ 
     // delete invite 
    } 
    else if(indexPath.section == kInvitesSentSection){ 
     // delete invite 
    } 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"%s:%d indexPath=%@", __FUNCTION__, __LINE__, indexPath); 
    // Return YES if you want the specified item to be editable. 
    return YES; 
} 

#pragma mark UITableViewDelegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    // do stuff here 
} 

편집 : 셀에 슬쩍 때 실제로 이러한 로그를 발견했습니다. 그러나 다른 셀을 스 와이프하면 로그가 없습니다. 이는 삭제 버튼이 활성화되었지만 탭할 수 없음을 나타냅니다. 왜?

2013-07-10 08:24:57.400 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=<NSIndexPath 0xc44b180> 2 indexes [0, 0] 
2013-07-10 08:24:57.400 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=<NSIndexPath 0xc44b180> 2 indexes [0, 0] 
2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=<NSIndexPath 0xc44b1b0> 2 indexes [0, 0] 
2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=<NSIndexPath 0xc44b1b0> 2 indexes [0, 0] 
2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:canEditRowAtIndexPath:]:369 indexPath=<NSIndexPath 0xc44b380> 2 indexes [0, 0] 
2013-07-10 08:24:57.401 Heartstream[35280:c07] -[SMInvitesViewController tableView:editingStyleForRowAtIndexPath:]:337 indexPath=<NSIndexPath 0xc44b380> 2 indexes [0, 0] 

답변

0

내 큰 부분에 매우 간단합니다. 앞서 언급했듯이 표준 UITableView 셀을 사용하면 효과적 이었지만 하위 클래스는 효과가 없었습니다. layoutSubviews를 무시하고 호출하지 않은 것으로 나타났습니다.

[super layoutSubviews];

Doh! X (

다른 사람에게 도움이 되었기를 바랍니다.