1

UIPickerViewUIToolbarUIBarButtonItemおよび をプログラムで作成していUIButtonます。カスタム ピッカーを textView の inputView として設定すると、[完了] ボタン以外はすべて問題なく動作します。

問題が何であるかを知っている人はいますか?

私が使用したコードは次のとおりです。

// initialize picker
CGRect cgRect =[[UIScreen mainScreen] bounds];
CGSize cgSize = cgRect.size;

_picker = [[UIPickerView alloc] init];
_picker.frame=CGRectMake(0, 0, cgSize.width, cgSize.height);
_picker.showsSelectionIndicator = YES;
_picker.delegate = self;

// toolbar of picker
UIToolbar* toolbar = [[UIToolbar alloc] init];
toolbar.frame=CGRectMake(0, 0, cgSize.width, 35);
toolbar.barStyle = UIBarStyleBlackTranslucent;

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

UIButton *customButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 33)];
[customButton setTitle:@"Done" forState:UIControlStateNormal];
[customButton addTarget:self action:@selector(doneClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barCustomButton =[[UIBarButtonItem alloc] initWithCustomView:customButton];

NSMutableArray * arr = [NSMutableArray arrayWithObjects:flexibleSpaceLeft, barCustomButton, nil];
[toolbar setItems:arr animated:YES];
self.txtTeam.inputView = _picker;
[_picker addSubview:toolbar];

そのdoneClicked方法は次のとおりです。

    -(void)doneClicked
{
    NSLog(@"Done button clicked.");
    [self.txtTeam resignFirstResponder];
}

ただし、[完了] ボタンはクリックできません。

4

3 に答える 3

3
UIButton *customButton =  [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setFrame:CGRectMake(0, 0, 30, 60)];
[customButton setTitle:@"Done" forState:UIControlStateNormal];
[customButton addTarget:self action:@selector(doneClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barCustomButton =[[UIBarButtonItem alloc] initWithCustomView:customButton];

このようにしてみてください..

于 2013-10-29T09:52:35.863 に答える
1

ボタンのセレクターが doneClicked: を呼び出すように設定しましたが、メソッドは doneClicked と呼ばれます。セレクターのメソッド名の末尾から : を削除すると、機能するはずです。

于 2013-10-29T09:34:55.370 に答える