2

我正在向操作表添加一个按钮。这很容易,但在我的情况下,有 5 个以上的按钮,Apple 不接受操作表上超过 5 个按钮。因此,我将滚动视图添加到操作表并将按钮添加到滚动视图。但是这个视图有两个固定按钮,一个是取消按钮,另一个是带有一些标题的按钮。

这是正确的方法吗?

4

2 回答 2

6

如果您有五个以上的按钮,最好在普通视图中使用自定义表格视图并给出UIModalTransitionStyleCoverVertical,这样它就会像操作表一样

于 2012-04-16T08:13:25.600 回答
1

使用以下代码....

- (IBAction)actionsheetbuttonpress:(id)sender {


actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                          delegate:nil
                                 cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                                 otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerDateToolbar sizeToFit];



CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

pickerData = [[UIPickerView alloc]initWithFrame:pickerFrame];
pickerData.showsSelectionIndicator = YES;
pickerData.dataSource = self;
pickerData.delegate = self;



[actionSheet addSubview:pickerData];


NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]initWithTitle:@"DONE-A" style:UIBarButtonItemStyleBordered target:self action:@selector(DatePickerDoneClick)];
UIBarButtonItem *doneBtn1 = [[UIBarButtonItem alloc]initWithTitle:@"DONE-B" style:UIBarButtonItemStyleBordered target:self action:@selector(DatePickerDoneClick)];
UIBarButtonItem *doneBtn2 = [[UIBarButtonItem alloc]initWithTitle:@"DONE-C" style:UIBarButtonItemStyleBordered target:self action:@selector(DatePickerDoneClick)];



[barItems addObject:doneBtn];
[barItems addObject:doneBtn1];
[barItems addObject:doneBtn2];
//add more two button here...or you can add any no of buttons..

[pickerDateToolbar  setItems:barItems animated:YES];

[actionSheet addSubview:pickerData];
[actionSheet addSubview:pickerDateToolbar];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
[barItems release];
[actionSheet release];
[pickerData release];

}

希望,这会帮助你....寒意

于 2012-04-16T08:12:08.717 回答