[英]TableView swipe-to-delete doesn't work
我有一個可編輯的分組表視圖,但滑動刪除不起作用。 看起來滑動刪除應該與 UITableViewCellEditingStyleDelete 一起出現,但對我來說似乎不是。 這是我的編輯風格方法:
- (UITableViewCellEditingStyle)tableView:(UITableView *)table editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1)
{
if (indexPath.row < [[device_coordinator getChannelList] count]) return UITableViewCellEditingStyleDelete;
else if (indexPath.row < [[device_coordinator getChannelList] count]+2) return UITableViewCellEditingStyleInsert;
}
return UITableViewCellEditingStyleNone;
}
這使表格看起來正確。 有些單元格在左側有插入圖標,有些單元格有刪除圖標,它們應該如此。 按下刪除圖標會出現刪除確認按鈕。 但是滑動不會!
即使我只是從我的 cellForRowAtIndexPath 方法返回空白的、新分配的單元格,它仍然不起作用,因此看來我的單元格中沒有任何內容導致問題。 同樣的問題發生在 4.3 模擬器和我的 iPod touch 2g 上。
我認為您的代碼是正確的,但如果我理解正確,則存在邏輯錯誤。 您想在編輯模式下滑動刪除,這是不可能的。 滑動刪除僅在用戶未處於編輯模式時有效。 所以你只需要通過調用這個方法來隱藏/顯示編輯圖標。
-(IBAction)edit:(id)sender//action connected to edit button
{
if(yourTableView.editing) [yourTableView setEditing:NO animated:YES];
else [yourTableView setEditing:YES animated:YES];
}
然后當單元格旁邊沒有圖標時,滑動刪除將起作用。 希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.