例子如下: NSMutableArray*buttonTitles =[NSMutableArray array]; if(condition1){ [buttonTitles addObject:@"Do action 1"]; } if(condition2){ [buttonTitles addObject:@"Do action 2"]; } if(condition3){ [buttonTitles addObject:@"Do action 3"]; } if(condition4){ [buttonTitles addObject:@"Do action 4"]; } [buttonTitles addObject:@"Cancel"]; UIActionSheet*actionSheet =[[[UIActionSheet alloc] initWithTitle: nil delegate: self cancelButtonTitle: nil destructiveButtonTitle: nil otherButtonTitles: nil] autorelease]; for(NSString*title in buttonTitles){ [actionSheet addButtonWithTitle: title]; } [actionSheet setCancelButtonIndex:[buttonTitles count]-1];