2009-12-18 7 views
0

uitableview에서 마지막 uitablviewcell을 제거하려고하는데 문제가 있습니다. 지금까지 가지고있는 코드가 있습니다.마지막 UITableViewCell을 제거하는 방법

[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[self.tableView numberOfRowsInSection:0]] withRowAnimation:NO]; 

나는 마지막 셀을 제거하겠습니까? 어떤 제안? 감사.

+0

-deleteRowsAtIndexPaths '의 두 번째 매개 변수 : withRowAnimation는 :의''BOOL' 아니다; 그것은'UITableViewRowAnimation' 유형입니다 – user102008

답변

1

섹션의 행 수가 0이 아닙니다 (즉, indexPath.row == 0 임에도 불구하고 1을 반환합니다). arrayWithObject : ([self.tableView numberOfRowsInSection : 0] - 1)을 시도하십시오.

또한 [self.tableView numberOfRowsInSection :]은 배열에 NSIndexPath 객체가 실제로 필요한 경우 NSInteger를 반환합니다. self 가정하면 뷰 컨트롤러, 당신은 하나 개 이상의 섹션이있는 경우

NSInteger temprowcount = [self.tableView numberOfRowsInSection:0]; 
if (temprowcount > 0) { 
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:temprowcount-1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; 
} 
1

, 이것은이 코드를 삽입 할 위치에 따라, 그것을해야 즉 tableView 포함하고 UITableViewDataSource 프로토콜에 준거 :

NSUInteger _lastSection = [self numberOfSectionsInTableView:tableView]; 
NSUInteger _lastRow = [tableView numberOfRowsInSection:_lastSection] - 1; 
NSUInteger _path[2] = {_lastSection, _lastRow}; 
NSIndexPath *_indexPath = [[NSIndexPath alloc] initWithIndexes:_path length:2]; 
NSArray *_indexPaths = [[NSArray alloc] initWithObjects:_indexPath, nil]; 
[_indexPath release]; 

[tableView beginUpdates]; 
[tableView deleteRowsAtIndexPaths:_indexPaths withRowAnimation:UITableViewRowAnimationNone]; 
[tableView endUpdates]; 

[_indexPaths release]; 
0

: 당신은 단지 테이블에 1 개 섹션이 가정

관련 문제