我創建了一個包含2個部分的表格,我希望應用程序在按下編輯按鈕時只顯示第一部分中的刪除按鈕而不是第二部分,我寫了如下代碼如何刪除只有一個部分中的行
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
Book_own *temp= (Book_own *)[self.books objectAtIndex:indexPath.row];
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[books removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
}
但是當我按Edit按鈕時,它顯示兩個部分中的刪除按鈕,我怎樣才能防止這種情況,並在第一部分進行刪除???
感謝您的幫助 –
難道這允許我做(didSelectRowAtIndexPath方法)? –
是的,你只能玩UITableViewCellEditingStyleNone;這意味着只在編輯樣式,但你的意思是UITableViewSelectionStyleNone我們沒有改變任何東西在它,這是負責射擊didselectrowatindexpath –