[英]UITableView Edit mode
I have UITableView
and I am trying to load it by default in edit mode. 我有
UITableView
,我试图在编辑模式下默认加载它。 The problem is when I this line table.editing=TRUE;
问题是当我这行
table.editing=TRUE;
my rows disappear, I implemented this methods: 我的行消失了,我实现了这个方法:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
but with no luck. 但没有运气。 What should I do?
我该怎么办?
as Anish pointed to using 正如Anish所指出的那样
[tableView setEditing: YES animated: YES];
But you need to have it in viewWillAppear
view event to make it work. 但是你需要在
viewWillAppear
视图事件中使它才能使它工作。
试试这个...
[tableView setEditing: YES animated: YES];
In ViewDidLoad write 在ViewDidLoad中写
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStyleBordered target:self action:@selector(addORDoneRows)];
[self.navigationItem setLeftBarButtonItem:addButton];
addORDoneRow addORDoneRow
- (void)addORDoneRows
{
if(self.editing)
{
[super setEditing:NO animated:NO];
[_dbSongsTblView setEditing:NO animated:NO];
[_dbSongsTblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[_dbSongsTblView setEditing:YES animated:YES];
[_dbSongsTblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@"Done"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
For MultipleSelection of Row 对于Row的MultipleSelection
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Note: There are Three Editiing Style as below 注意:有三种编辑风格如下
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
Note: And for multiple Selection set Selection and Editing Style to Multiple from Attribute inspector 注意:对于多个选择集,从属性检查器中选择和编辑样式为多个
To load a tableView in edit mode you should call setEditing(true, animated: false)
in viewDidLoad()
. 要在编辑模式下加载tableView,您应该在
viewDidLoad()
调用setEditing(true, animated: false)
viewDidLoad()
。
If your view controller is a subclass of UITableViewController
there's no need to change, just make the above call. 如果您的视图控制器是
UITableViewController
的子类,则无需更改,只需进行上述调用即可。 Otherwise if your view controller is a subclass of UIViewController, then you should make a call in this way: tableView.setEditing(true, animated: true)
. 否则,如果您的视图控制器是UIViewController的子类,那么您应该以这种方式进行调用:
tableView.setEditing(true, animated: true)
。
Tested with Swift 2.2. 用Swift 2.2测试。
[self.tableView setEditing:!self.tableView.isEditing animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.