0

こんにちは私はtableView私の視野の中にあります。しかし、ナビゲーションバーでの編集がtableViewで機能するようにしたいと思います。これを行う方法を教えてください。

メインビュー用にナビゲーションバーを設定しtableView、同様に設定しました。

ナビゲーションバーの作成メソッドを作成しました。

- (UINavigationBar *)createNavigationBar
{
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:@"Task Manager"];
UINavigationBar *new = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:nil];
title.leftBarButtonItem = addButton;
[new pushNavigationItem:title animated:YES];
UIColor *color = UIColorFromRGB(0xff8c00); // Dark orange
new.tintColor = color;
return new;
}

私が持っています

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

同様に設定します。

基本的に、メインナビゲーションバーの編集ボタンをタップしたときに、サブテーブルビューに赤い円が表示される必要があります。

はっきりしなかったらごめんなさい。説明が必要な場合は、私に尋ねてください。

ありがとう!:)

4

3 に答える 3

0

tableViewを編集モードにする必要があります..このように行うことができます

[yourTableView setEditing:YES animated:YES];

このコードをボタンアクションに配置します。したがって、コードを次のように変更する必要があります。

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editPressed)];
于 2012-07-02T07:36:08.580 に答える
0

現在の編集状態を保存するためのBOOL変数と、addTargetこの変数に基づいてテーブルを編集モードにする編集ボタンへの関数()が必要です。

-(IBAction) editWasPressed:(id)sender
{
    editMode = ! editMode;

    if(editMode) 
    {
        [table setEditing:YES animated:YES];
    }
    else
    {
        [table setEditing:NO animated:YES];
    }
}

名前の付いた変数の名前newを別の名前に変更する必要があります。

于 2012-07-02T07:37:37.013 に答える
0

ビューにこの行を作成しますWillApear: ..。

[super setEditing:NO animated:yes];

次に、editWasPressed:メソッドで...

[my_table setEditing:!my_table.editing animated:YES];

これがお役に立てば幸いです。

于 2012-07-02T08:10:20.527 に答える