use*_*509 42 iphone editmode uitableview ios
我有UITableView,我正在尝试在编辑模式下默认加载它.问题是当我这行table.editing=TRUE;我的行消失时,我实现了这个方法:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
但没有运气.我该怎么办?
Ahm*_*ali 61
正如Anish所指出的那样
[tableView setEditing: YES animated: YES];
Run Code Online (Sandbox Code Playgroud)
但是你需要在viewWillAppear视图中使用它才能使它工作.
Ani*_*ish 10
试试这个...
[tableView setEditing: YES animated: YES];
Run Code Online (Sandbox Code Playgroud)
在ViewDidLoad中写
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStyleBordered target:self action:@selector(addORDoneRows)];
[self.navigationItem setLeftBarButtonItem:addButton];
Run Code Online (Sandbox Code Playgroud)
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];
}
}
Run Code Online (Sandbox Code Playgroud)
对于Row的MultipleSelection
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Run Code Online (Sandbox Code Playgroud)
注意:有三种编辑风格如下
UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert
Run Code Online (Sandbox Code Playgroud)
注意:对于多个选择集,从属性检查器中选择和编辑样式为多个
| 归档时间: |
|
| 查看次数: |
53929 次 |
| 最近记录: |