2010-11-22 6 views
2

NIBを使用せずに自分のアプリケーションでUITableViewを取得しました。しかし、私はこのようにしているので、通常は通常のUITableViewに関連する編集プロパティを取得できません。たとえば、代わりに@interface TableViewController:UITableViewContollerを使用し、ナビゲーションバーにeditButtonItemを追加すると、削除ボタンと移動行がそのボタンを押すと自動的にインクルードされます。プログラムでUITableViewの編集プロパティを呼び出すにはどうすればいいですか?

しかし、何も私のUITableViewで動作しません。助けてください。

// in .h 
@interface TableViewController : UIViewController 
<UITableViewDelegate, UITableViewDataSource> 
{ 
UITableView *tView; 
NSMutableArray *aMutArray; 
} 



    // in .m 
    -(id)init 
    { 
    [super initWithNibName:nil bundle:nil]; 

    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]]; 
    [[self navigationItem] setTitle:@"ReorderingTableCell"]; 

    return self; 
    } 

    - (void)loadView 
    { 
    [super loadView]; 

    CGRect tableFrame = CGRectMake(0, 0, 320, 300); 
    tView = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain]; 
    [[self tView] setDelegate:self]; 
    [[self tView] setDataSource:self]; 

    aMutArray = [[NSMutableArray alloc] initWithObjects:@"first", @"second", @"third", nil]; 

    [[self view] addSubview:tView]; 
    } 

、その後のようなデリゲートメソッドの束:私は新しいを作成するので、私はデリゲートメソッドの詳細を通過する必要はありません

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath, 
- (void)setEditing:(BOOL)flag animated:(BOOL)animated 

等...

単純なUITableViewControllerを使ってプロジェクトを作成してください。

私はコードを実行すると、私はブレークポイントを設定し、デリゲートメソッドが呼び出されますが何も起こりません。セルの左側に削除アイコンが表示されず、右側にセルアイコンが表示されません。何も起こりません。

ありがとうございます!

答えて

5

テーブルビューを編集モードにしたり編集モードから外したりするには、-[UITableView setEditing:animated:]に電話する必要があります。

+0

ありがとうsoooo !!!! – okysabeni

関連する問題