0

我想将按钮添加到UIActionSheet.

UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Select Album"
                            delegate:self
                            cancelButtonTitle:@"Cancelled"
                            destructiveButtonTitle:nil
                            otherButtonTitles:nil];


for (int i =0; [groups count]; i++) 
{
      [as addButtonWithTitle:[groups objectAtIndex:i]];    
}

[as showInView:self.view];

但按钮没有显示。

4

3 回答 3

2

试试这个:

 actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Font Name?"
                                          delegate:self
                                 cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                                 otherButtonTitles:@"OK", nil];

 UIToolbar *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(dismissActionSheet)];
 [barItems addObject:doneBtn];

[pickerDateToolbar setItems:barItems animated:YES];

[actionSheet addSubview:pickerDateToolbar];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320,390)];//set it with your way

可能会有所帮助。快乐的编码...

于 2013-10-26T08:21:03.963 回答
0

I ran the piece of code and it worked fine for me. Check the groups array,it is supposed to be an array of NSString objects. Try adding cancel button in the end. Refer this--> Use NSArray to specify otherButtonTitles?

于 2013-10-26T07:35:55.023 回答
0
for (int i = 0; i < groups.count; i++)
于 2013-10-26T12:08:22.827 回答