我已经以编程方式创建了一个UIActionsheet但是我无法弄清楚如何将它链接到现有的IBAction。
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.label.text = @"Destructive Button Clicked";
}}
这是我的代码,我点击一个按钮,我希望它链接到我已经拥有的以下IBAction。
- (IBAction)doButton;
那么,我该怎么做呢?任何帮助将不胜感激。 感谢
答案 0 :(得分:1)
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex {
if (buttonIndex == 0) {
self.label.text = @"Destructive Button Clicked";
[self doButton];
}
}
答案 1 :(得分:0)
最好的方法是在你的班级中添加一个UIActionSheet委托,并在你的IBAction中调用行动表。
.h文件
@interface ViewController : UIViewController <UIActionSheetDelegate>
-(IBAction)doButton;
@end
.m文件
-(IBAction)doButton {
UIActionSheet *doSheet = [[UIActionSheet alloc] initWithTitle:@"Your title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Button 0", @"Button 1", nil];
[doSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex {
if (buttonIndex == 0) {
//Do Something
}
if(buttonIndex == 1) {
//Do Something else
}
}