2013-10-24 2 views
2

사용자 정의 셀을 UITableView 용으로 사용 중이며 UIButton이 있으므로 테이블보기에서 현재 셀을 제거해야합니다. cellForRowAtIndexPath에서 나는 올바른 셀UITableView에서 사용자 정의 셀을 제거 할 수 없습니다.

-(void) removing 
{ 
    [TOperations deleteTickerFromGroup:tickerGroupID andTickerSymbol:selectedSymbol]; 

    NSNumber *selectedRowIndex1 = [NSNumber numberWithInteger:currentIndexPath.row]; 
    [tableView1 beginUpdates]; 
    NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedRowIndex1.integerValue-1 inSection:0]; 
    [tableView1 endUpdates]; 
    [tableView1 reloadData]; 

} 

이제 문제는이 표시되어 있는지 애니메이션을 제거

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"CellIdentifier"; 
    NSLog(@"Creating Cell"); 

    FADynamicCell *cell= (FADynamicCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([FADynamicCell class]) 
              owner:nil 
              options:nil] lastObject]; 
    } 

    currentIndexPath = indexPath; 

    UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    removeButton.tag = indexPath.row +100; 
    removeButton.frame = cell.removeButton.frame; 
    removeButton.backgroundColor = [UIColor colorWithRed:255./255 green:65./255 blue: 21./255 alpha:1]; 
    removeButton.titleLabel.font = [UIFont systemFontOfSize:12]; 
    removeButton.titleLabel.textAlignment = NSTextAlignmentCenter; 
    [removeButton setTitle:@"Remove" forState:UIControlStateNormal]; 
    [removeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [removeButton addTarget:self action:@selector(removing) forControlEvents:UIControlEventTouchUpInside]; 
    [cell addSubview:removeButton]; 

    return cell; 
} 

그리고 기능에

을하고있는 중이 야하지만 난 테이블에서 사용자 정의 셀을 제거 할 수 없습니다입니다 전망. 그리고 다시보기를로드 할 때마다, 즉 다른 화면에서 오는 경우 제거를 위해 클릭 한 셀이 표시되지 않습니다.

어떤 도움을 이해할 수있을 것이다 ...

+0

데이터 소스에 문제가있을 수 있습니다. 다른 화면에서 왔을 때 항목이 남아 있는지 확인하십시오. –

+0

@Sviatoslav Yakymiv : 위의 코드에서 @Atul 이전에 – Atul

+0

@Atul 버튼을 눌렀다면 다른 화면에서 들어 왔을 때 테이블 뷰의 데이터 소스가 누락 된 것 같습니다. –

답변

2

테이블보기에서 행/셀을 삭제하려면, 당신은 당신의 UITableView 인스턴스에서 deleteRowsAtIndexPaths:withRowAnimation: 메소드를 호출 할 필요가있다.

NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedRowIndex1.integerValue-1 inSection:0]; 
[self.yourTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade]; 

이렇게하면 UI가 업데이트되지만 데이터 소스에서도 해당 행을 삭제해야합니다. 이렇게하면 완전히 삭제됩니다.

희망 하시겠습니까?

+0

: 코드 코드를 사용하면 충돌이 발생하고 다음과 같이 표시됩니다. *** 캐치되지 않은 예외 'NSInternalInconsistencyException'으로 인해 앱을 종료합니다. 이유 : '유효하지 않은 업데이트 : 섹션 0의 행 수가 잘못되었습니다. 기존 섹션에 포함 된 행 수 update (3)가 update (3) 이전에 해당 섹션에 포함 된 행 수와 같거나 그 섹션 (삽입 된 0, 삭제 된 1)에서 삽입되거나 삭제 된 행 수를 더하거나 뺀 다음 더하기 또는 빼기 해당 섹션에서 또는 밖으로 이동 된 행 수 (0은 이동, 0은 이동). ' – Atul

+2

이것은 numberOfRowsForSection 메서드에서 동일한 수의 행을 반환하는 데이터 소스를 업데이트하지 않기 때문에 발생합니다. – micantox

+0

@Atul indexPath가 올바르게 계산되고 있습니까? 또한 특정 행을 데이터 소스에서 삭제해야합니다. – Amar

관련 문제