2012-01-11 68 views
0

我有一個簡單的問題。我有一個UITableView,您可以在其中添加和刪除單元格。如果第一個tableViewCell被刪除,我想要發生其他事情。我如何測試以查看FIRST單元是否已通過使用if聲明刪除?測試UITableViewCell是否已被刪除

if(//how do i test?) 
{ 
//DO SOMETHING HERE!! 
} 

感謝大家的幫助!

回答

1

我假設你已經有了一個對的UITableViewCell,你要刪除,它生活在UITableView的一個參考。如果是這樣,只是做

NSIndexPath indexPath = [tableView indexPathForCell:deletedCell]; 

,並期待在indexPath.row確定行。請注意,您必須在單元格實際從表格視圖中刪除/移除之前執行此操作。

+0

好的,如果我在我的'cellForRow'方法中創建了一個UITableViewCell,那麼這可能是你正在談論的引用嗎?我怎麼把這個放到'if'語句中呢?非常感謝答覆! :D – iProRage 2012-01-11 04:17:12

+0

你最初如何刪除單元格?推測它必須涉及你將要刪除的單元格。 – UIAdam 2012-01-11 05:12:45

+0

好吧,我打電話'commitEditingStyle'方法,在裏面我有 'if(editingStyle == UITableViewCellEditingStyleDelete) {[self cell] removeObjectAtIndex:[indexPath row]]; [[self imageArray] removeObjectAtIndex:[indexPath row]]; NSArray * indexPaths = [NSArray arrayWithObject:indexPath]; [[self myTableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; }' – iProRage 2012-01-11 23:20:03