1

UIToolbar の UIBarbuttonItem の非表示、削除、または追加について質問があります。

UIToolbar と 2 つの項目があります。ツールバーの項目を非表示にしたいのですが、たとえば 3 番目の UITableview に入ると表示されます。

このコードをviewDidloadに入れました

 instruct = [[UIBarButtonItem alloc]

  initWithImage:[UIImage imageNamed:@"b_info.png"] style:UIBarButtonItemStylePlain target:self action:@selector(instruct_clicked:)];

instruct.title =@"instructions";



spacebetween = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

items = [NSMutableArray arrayWithObjects:vorige, spacebetween, aanwijzingen, spacebetween, nil];


[toolbar setItems:items] 

今私が望むのは、私のプログラムのある瞬間に、ツールバーに別の項目を追加する関数を呼び出すことです。

例はこちら

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

... .. 
... 
... 
//and then something like this 

[items addObject: anotherButton];

[ツールバー setItems:アイテム]

}

mutableArray に別のアイテムを追加するだけでよいと考えましたが、残念ながら役に立ちませんでした。誰にも手がかりやアイデアがありますか。

4

1 に答える 1

2

itemsNSMutableArray になりたい場合は、それを宣言する必要があります。普通の NSArray には何も追加できません。

[toolbar setItems:items]コメントの後に編集: の後にもう一度行う必要があります[items addObject:anotherButton]

于 2009-08-17T10:16:36.070 に答える