使用showInView时,Actionsheet按钮不响应

时间:2013-07-03 05:25:39

标签: objective-c xcode4.5 uiactionsheet ios6.1

我的程序中有这段代码

- (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内的UITabBarController。 谁知道如何解决这个问题?非常感谢你的帮助。谢谢!

1 个答案:

答案 0 :(得分: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];