Ios 将UIAlertController与tabbarcontroller一起使用
我在tabbarcontroller的一个选项卡中使用actionsheet。所以它的工作原理是这样的,当我点击tab按钮时,它会显示actionsheet。我使用的代码是Ios 将UIAlertController与tabbarcontroller一起使用,ios,objective-c,uialertcontroller,Ios,Objective C,Uialertcontroller,我在tabbarcontroller的一个选项卡中使用actionsheet。所以它的工作原理是这样的,当我点击tab按钮时,它会显示actionsheet。我使用的代码是 UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"someText",
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];
现在,当我运行这段代码并切换到选项卡时,我得到一个崩溃消息,说
应用程序试图在目标上呈现无模式视图控制器
我做错了什么?我们可以将UIAlertController与tabbarcontroller一起使用吗
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self actionSheetInit];#this where actionsheet is called
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
什么是自我?选项卡栏上的视图控制器?你能验证
actionSheet
是否为非零吗?@JAL是的,它是选项卡栏上的一个视图控制器,如何检查actionSheet是否为非零?在显示它之前,使用调试器并确保actionSheet
不为零。@JAL是的,当我购买actionSheet时它显示为零,该怎么办?我无法用你提供的代码重现它。出于测试目的,我将您的代码放在一个空视图控制器的viewdide
方法中。你在哪里调用这个代码?