我能夠解決這個問題,但遺憾的是,它需要額外的工作,並不像設置一些屬性一樣簡單。
在我
- (UITableViewCellEditingStyle)tableView:(UITableView *)_tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
方法我返回UITableViewCellEditingStyleNone
讓我的自定義editingAccessoryView
會顯示出來。在這種方法我也這樣做:
self.tableView.scrollEnabled = NO;
if(self.editingPath)
{
[[tableView cellForRowAtIndexPath:editingPath] setEditing:NO animated:YES];
}
self.editingPath = indexPath;
for (UITableViewCell *cell in [tableView visibleCells])
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
這將禁用滾動,然後存儲我們刷卡,供以後使用indexPath
。如果你在另一行上滑動,在編輯一行時,它會將第一行編輯並編輯第二行,這就是蘋果應用程序的行爲方式。我還將所有可見單元上的單元格selectionStyle
設置爲UITableViewCellSelectionStyleNone
。這可以減少用戶在當前正在編輯的時候選擇另一個單元格時的藍色閃爍。
接下來我們需要在點擊另一個單元時關閉accessoryView
。要做到這一點,我們實現此方法:
-(NSIndexPath *)tableView:(UITableView *)_tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.editingPath)
{
UITableViewCell *c = [tableView cellForRowAtIndexPath:self.editingPath];
[c setEditing:NO animated:YES];
self.tableView.scrollEnabled = YES;
self.editingPath = nil;
for (UITableViewCell *cell in [tableView visibleCells])
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return nil;
}
return indexPath;
}
這樣做是什麼時候有人要點擊一個細胞,如果我們說了unedit細胞,然後編輯並返回什麼。
也
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
我回到YES
,使上我希望用戶能夠刪除單元格編輯。
@jrturton我得到同樣的問題..我已經參考http://stackoverflow.com/questions/7295834/custom-editingaccessoryview-not-working?lq=1。你能告訴我你在代碼中做了什麼改變的解決方案,謝謝! –