2012-01-23 6 views
1

ピッカーをAdd UIPickerView & a Button in Action sheet - How?で実装しています。 UISegmentedControlをUIButtonに置き換えようとしましたが、うまくいきません。 UIButtonをここに表示できない理由を誰かに教えてもらえますか?UIPickerViewを持つUIActionSheetにUIButtonを配置して配置します。

ありがとうございます。

- (IBAction) makeButtonPressed: (id) sender; 
{ 
    UIActionSheet *actionSheet = [[UIActionSheet alloc] init]; 
    [actionSheet setTitle:@"Select Make"]; 
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackOpaque]; 

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 0, 0)]; 
    pickerView.dataSource = self; 
    pickerView.delegate = self; 
    pickerView.showsSelectionIndicator = YES; 
    [actionSheet addSubview:pickerView]; 

// UISegmentedControl *doneButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]]; 
// doneButton.momentary = YES; 
// doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
// doneButton.segmentedControlStyle = UISegmentedControlStyleBar; 
// doneButton.tintColor = [UIColor blackColor]; 
// [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged]; 
// [actionSheet addSubview:doneButton]; 

    UIButton *doneButton = [[UIButton alloc] init]; 
    doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    [doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged]; 
    [actionSheet addSubview:doneButton]; 

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]]; 

    [actionSheet setBounds:CGRectMake(0, 0, 320, 460)]; 
} 

答えて

3

UIButtonのための指定イニシャライザは+buttonWithType:です。あらかじめ定義されたスタイルのいずれかを使用してボタンを作成するか、UIButtonTypeCustomを使用する必要があります。

UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeRoundRect]; 
doneButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 
[doneButton addTarget:self action:@selector(makeDone:) forControlEvents:UIControlEventValueChanged]; 
[actionSheet addSubview:doneButton]; 
+0

ありがとうございます、それは動作します – ThinkChris

関連する問題