0

我的程序上有这个代码

- (void)viewDidLoad
{
[super viewDidLoad];

UIButton *saveMessageBtn =  [UIButton buttonWithType:UIButtonTypeCustom];
[saveMessageBtn setImage:[UIImage imageNamed:@"btn_done.png"] forState:UIControlStateNormal];
[saveMessageBtn addTarget:self action:@selector(saveMessage) forControlEvents:UIControlEventTouchUpInside];
[saveMessageBtn setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:saveMessageBtn];
}

-(IBAction)saveMessage:(id)sender{


UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send Now",@"Non Recurring",@"Recurring", nil];
[actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *) actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 0){
    NSLog(@"Send Now");
}
else if (buttonIndex == 1){
    [self performSegueWithIdentifier:@"modalNonRecurring" sender:self];
}
else if (buttonIndex == 2){
    [self performSegueWithIdentifier:@"modalRecurring" sender:self];
}
else{
NSLog(@"Cancel Clicked");
    }
}

正如您在代码中看到的,它应该在单击特定按钮时执行 segue 或执行“NSLog”。

但是当我单击一个按钮时,它不会执行我想要它执行的操作,而是在调试区域中显示此消息。

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

顺便说一句,我使用的UINavigationController是 a 里面的 a UITabBarController。任何人都知道如何解决这个问题?您的帮助将不胜感激。谢谢!

4

1 回答 1

0

在 .h 文件中添加UIActionSheetDelegate委托并尝试这样它就可以工作了。

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Send Now",@"Non Recurring",@"Recurring", nil];
    actionSheet.delegate = self;
    [actionSheet showInView:self.view];
于 2013-07-03T05:34:57.403 回答