0
基本上,當您選擇特定的行時,我會從表格視圖中移除所有行並將其移除。爲此,我有以下代碼:沒有從didSelectRowAtIndexPath踢入的單元格刪除動畫:
-(void)removeRows:(int)i
{
NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:0];
UITableViewCell *cell = [_table cellForRowAtIndexPath:ip];
CGRect newFrame;
if(i%2==0){
newFrame = cell.frame;
newFrame.origin.x = -[UIScreen mainScreen].bounds.size.width;
}else{
newFrame = cell.frame;
newFrame.origin.x = [UIScreen mainScreen].bounds.size.width;
}
[UIView animateWithDuration:0.2 delay:0 options:0
animations:^{cell.frame = newFrame;}
completion: ^(BOOL finished){
if(i == 0){
[dataSource removeAllObjects];
[_homeScreenView.proustPacks reloadData];
}
}];
}
對於每一行都以相反順序調用此方法。現在的一切,當用戶點擊一個特定的細胞的偉大工程,如果我用它爲我的刪除按鈕(這是不是的tableView的一部分),但現在我想相同的動畫和動作,是這樣的:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([(Something*)[dataSource objectAtIndex:indexPath.row] isWhatIWant]){
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(remove) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(goToNext:) userInfo:nil repeats:NO];
}
}
在哪裏「goToNext:」 推動下一個控制器的navigationController和removePacks是:
-(void)remove{
int aux = _dataSource.count -1;
for(int i=aux;i>=0;i--){
[self removeRows:i];
}
}
我的方法已經工作並刪除了行。問題是我沒有在每一行上獲得我的動畫。 – Busu
這是因爲您正在手動執行動畫。 UITableView有一個用於這個'deleteRowsAtIndexPaths:withRowAnimation:' –
的方法,或者如果你想單獨刪除它們,只需要給它帶一個索引路徑的NSArray。 –