Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用UITableControllerDelegate方法_Ios_Objective C_Iphone_Uitabbarcontroller - Fatal编程技术网

Ios 未调用UITableControllerDelegate方法

Ios 未调用UITableControllerDelegate方法,ios,objective-c,iphone,uitabbarcontroller,Ios,Objective C,Iphone,Uitabbarcontroller,我有一个选项卡栏控制器,它有4个选项卡,我想:当点击第4个选项卡(虚拟viewcontroller)时,它将显示一个新的viewcontroller,而不显示虚拟VC 这是我的密码: - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { NSLog(@"called"); AskQ

我有一个选项卡栏控制器,它有4个选项卡,我想:当点击第4个选项卡(虚拟viewcontroller)时,它将显示一个新的viewcontroller,而不显示虚拟VC

这是我的密码:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSLog(@"called");
    AskQuestionViewController *AQVC = [[AskQuestionViewController alloc]initWithNibName:@"AskQuestionViewController" bundle:nil];
    if (viewController == [tabBarController.viewControllers objectAtIndex:3])
    {
        [self presentViewController:AQVC animated:YES completion:nil];
        return NO;
    }
    return YES;
}
在我的viewDidLoad方法中,我设置了委托。
self.tabBarController.delegate=self

但是,由于某些原因,没有调用此方法。 有人能帮忙吗?

您需要使用:

- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
告诉代理用户在选项卡栏中选择了一项

询问代理是否应激活指定的视图控制器


因为这个类是一个tabBarController,很明显UITabBarController类没有一个名为tabBarController的属性。
因此,我只是将
self.tabBarController.delegate=self
设置为
self.delegate=self

行中的delgate=self有任何警告吗?@T\u 77没有。在我的.h文件中,我添加了UITabaBarControllerDelegate。无论如何,你需要告诉代理你点击了第四个选项卡,你可以在点击第四个选项卡后调用视图控制器。请尝试此操作,并让我知道是否发生任何问题。我将self.tabBarController.delegate=self更改为self.delegate=self。由于此类是tabBarController,显然UITabBarController类没有名为tabBarController的属性。您在哪里调用此委托方法?您需要在viewDidLoad()中分配委托如果您的类正在实现UITabBarController do self.delegate=self而不是self.tabController?.delegate=self,那么这是可行的,但我不知道这是不是一个好的解决方案?@Gellert您是我的英雄:-)
- tabBarController:shouldSelectViewController: