为了获得如上图所示的所需结果......我向您推荐编程方法比 xib 方法更好
我认为您正在尝试使用“完成”按钮实现选择器操作表。我将参考使用 segemnt 控件而不是使用工具栏。
在要显示带有选择器和完成按钮的操作表的位置使用以下代码。
UIActionSheet *Example_Actionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
Ex_Picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 0, 0)];
Ex_Picker.delegate = self;
Ex_Picker.showsSelectionIndicator = YES; // note this is default to NO
Example_Actionsheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[Example_Actionsheet addSubview:Bedroom_Picker];
[Example_Actionsheet showInView:self.view];
[Example_Actionsheet setBounds:CGRectMake(0, 0, 320, 485)];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blueColor];
[closeButton addTarget:self action:@selector(Close_method) forControlEvents:UIControlEventValueChanged];
[Example_Actionsheet addSubview:closeButton];
[Example_Actionsheet release];
如果你想使用工具栏
pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
[barItems addObject:doneBtn];
[pickerDateToolbar setItems:barItems animated:YES];
并在操作表的子视图中添加工具栏和选择器。
[aac addSubview:"Your toolbar"];
[aac addSubview:"Your picker"];
并设置动作表框架。它使用工具栏完成。