i need to add button dynamically in UIActionSheet in iphone.Please help me.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With