将UIAlertController与tabbarcontroller一起使用

时间:2015-11-25 06:00:37

标签: ios objective-c uialertcontroller

我在tabbarcontroller的其中一个标签中使用了动作表。所以它的工作是这样的,当我点击选项卡按钮它显示我的动作表。我正在使用的代码就是这个

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"someText",nil];
sheet.tag = 1;
[sheet showFromTabBar:application.tabBarController.tabBar];

然后我使用委托方法点击按钮,它工作正常。

然后我决定改为UIAlertcontroller,我正在使用的代码就是这个

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        #do something
    }];
UIAlertAction *sButton = [UIAlertAction actionWithTitle:@"Send" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        #do something
    }];
[actionSheet addAction:sButton];
[actionSheet addAction:cancelButton];
[self presentViewController:actionSheet animated:YES completion:nil];

现在,当我运行此代码并切换到选项卡时,我正在崩溃说

  

应用程序尝试在目标

上显示nil模态视图控制器

我做错了什么?我们可以将UIAlertController与tabbarcontroller一起使用吗?

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self actionSheetInit];#this where actionsheet is called
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

0 个答案:

没有答案
相关问题