UIActionSheet dynamic Add button, uiactionsheet dynamic
Code:
ViewController. h
@interface ViewController : UIViewController<UIActionSheetDelegate>@end
ViewController. m
# Pragma-mark-functions // click any part to bring up UIActionSheet-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "title" delegate: self cancelButtonTitle: nil destructiveButtonTitle: nil otherButtonTitles: nil, nil]; // Add buttons one by one (for example, an array loop) [sheet addButtonWithTitle: @ "Item A"]; [sheet addButtonWithTitle: @ "Item B"]; [sheet addButtonWithTitle: @ "Item C"]; // Add a Cancel button [sheet addButtonWithTitle: @ "Cancel"]; sheet. cancelButtonIndex = sheet. the numberOfButtons-1; [sheet showInView: self. view] ;}# pragma-mark-UIActionSheetDelegate-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex {NSLog (@ "-- buttonIndex -- % ld ", buttonIndex );}