![](/img/trans.png)
[英]Change the color of default red color delete button in UITableViewCell when swiping rows or click on edit button
[英]my edit button can not change to done, delete row by swiping
我正在使用UITableView,正在刪除。 據我所知,有兩種刪除行的方法
從左向右滑動,將顯示“刪除”按鈕,以便您進行刪除
在右上角或右上角添加EDIT按鈕。 通過單擊它,“編輯”將更改為“完成”,並且表格的每一行將在每個行前面帶有一個帶(-)號的紅色圓圈。 點擊它,將出現刪除按鈕,您可以進行處理
我注意到,如果您確實有一個EDIT按鈕並使用方法1刪除,則EDIT按鈕也將更改為DONE...。但是,在將其滑動后,我的仍然是EDIT。 是否有人之前遇到過此問題,請幫忙。 歡迎在這里發表所有評論。 謝謝
當視圖不處於編輯模式時,滑動以刪除。 它應該是瀏覽視圖時刪除項目的快速方法。 例如,查看它在Mail應用程序中的工作方式-您可以點擊以編輯所有行,也可以滑動以刪除其中的一行。
因此,基本上它可以正常工作。
但是,如果要覆蓋標准行為,則可以在viewController上調用setEditing:來以編程方式切換模式,這也會更新編輯按鈕。
使用ViewdidLoad方法添加“編輯”按鈕
-(void)viewDidLoad;
{
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [self editButtonItem];
}
而對於刪除方法
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
[array removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPath:[NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationFade];
[self.tableView reloadData];
}
要獲得此行為,您需要實現以下兩個委托方法:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.editing = YES;
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
self.editing = NO;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.