43

私は持ってい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;
 }

しかし運がない。私は何をすべきか?

4

5 に答える 5

62

アニッシュが使用を指摘したように

[tableView setEditing: YES animated: YES]; 

viewWillAppearただし、それを機能させるには、ビューイベントに含める必要があります。

于 2011-05-14T12:39:06.470 に答える
10

これを試して...

[tableView setEditing: YES animated: YES];
于 2011-05-14T12:37:35.247 に答える
7

ViewDidLoad に書き込みます

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style: UIBarButtonItemStyleBordered target:self action:@selector(addORDoneRows)];
[self.navigationItem setLeftBarButtonItem:addButton];

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];
    }
}

行の複数選択の場合

 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleNone;
}

注: 以下の 3 つの編集スタイルがあります。

UITableViewCellEditingStyleNone,
UITableViewCellEditingStyleDelete,
UITableViewCellEditingStyleInsert

注: また、複数の選択セットの場合、属性インスペクターから [選択と編集スタイル] を [複数] に設定します。

于 2014-09-02T11:49:36.547 に答える
0

[self.tableView setEditing:!self.tableView.isEditing アニメーション:YES];

于 2016-06-09T19:38:21.770 に答える