[Code Note] iOS-UIActionSheet dynamic Add button, uiactionsheet dynamic
I ,.
Ii. Code.
RootViewController. h
# Import <UIKit/UIKit. h> @ interface RootViewController: UIViewController <UIActionSheetDelegate> @ end
RootViewController. m
// Click anywhere 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 at the same time [sheet addButtonWithTitle: @ "Cancel"]; sheet. cancelButtonIndex = sheet. the numberOfButtons-1; [sheet showInView: self. view];}