Anju
Anju

Reputation: 524

add buttons on actionsheet. and buttons should be more than 5

I am adding a button to an actionsheet. That's easy, but in my case there are more than 5 and Apple does not accept more 5 buttons on action sheet. So I add a scroll view to the actionsheet and add buttons to the scrollview. But this view has two fixed buttons that is cancel and one other with some title.

Is this the right way to do this?

Upvotes: 2

Views: 512

Answers (2)

Nitin
Nitin

Reputation: 7471

Use following code....

- (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];

}

Hope, this will help you....chill

Upvotes: 1

Charan
Charan

Reputation: 4946

if you have more than five buttons, its better to use a customized table view in normal view and give UIModalTransitionStyleCoverVertical so that it will come like an action sheet

Upvotes: 6

Related Questions