Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add button dynamically in UIActionSheet in iphone

Tags:

iphone

i need to add button dynamically in UIActionSheet in iphone.Please help me.

like image 664
Nitin Avatar asked Dec 28 '22 02:12

Nitin


1 Answers

Just alloc and init a new UIActionSheet instance and add the buttons one after another using –addButtonWithTitle:. This method returns you the index at which the button has been added to. You can then set the Index of the destructive button via -setDestructiveButtonIndex.

Here is an example that adds one button and adds another one if the boolean value useDestructiveButton is YES (and directly sets it as destructive button, making it red):

UIActionSheet *sheet = [[UIActionSheet alloc] init];
[sheet addButtonWithTitle:@"Button 1"];
if (useDestructiveButton) {
    [sheet setDestructiveButtonIndex:[sheet addButtonWithTitle:@"Button 2"]];
}

Don't forget to call the appropriate show method.

like image 140
Björn Marschollek Avatar answered Jan 11 '23 11:01

Björn Marschollek