Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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 在UITabbarController中,第二个选项卡总是灰显_Ios_Uitabbarcontroller - Fatal编程技术网

Ios 在UITabbarController中,第二个选项卡总是灰显

Ios 在UITabbarController中,第二个选项卡总是灰显,ios,uitabbarcontroller,Ios,Uitabbarcontroller,我正在尝试使用应用程序委托中的以下代码将两个NavBar控制器嵌入到UITabbarController中: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [window makeKeyAndVisible]; // Configure and show the window. FirstView

我正在尝试使用应用程序委托中的以下代码将两个NavBar控制器嵌入到UITabbarController中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [window makeKeyAndVisible];

    // Configure and show the window.

    FirstViewController *firstController = [[FirstViewController alloc] initWithNibName:nil bundle:NULL];
    self.firstNav = [[UINavigationController alloc] initWithRootViewController:firstController];
    SecondTableViewController *anotherOne = [[SecondTableViewController alloc] initWithNibName:nil bundle:NULL];
    self.anotherNav = [[UINavigationController alloc] initWithRootViewController:anotherOne];

    NSArray *twoViewControllers = [[NSArray alloc]initWithObjects:self.anotherNav,self.firstNav, nil];

    self.tabBarController = [[UITabBarController alloc]init];
    [self.tabBarController setViewControllers:twoViewControllers];
    [window addSubview:self.tabBarController.view];
    [window setRootViewController:tabBarController];
    return YES;
}   
这两个选项卡显示得很好,带有它们的名称,但我只能选择第一个选项卡,第二个选项卡总是灰显,不响应触摸事件。我将navController指定反转到选项卡栏中(即在数组TwoViewController中),每个视图都显示良好(在第一个选项卡中)

应用程序委托未实现UITabbarDelegate和UITabbarController delegate。我不使用故事板

第二个选项卡总是灰显的原因是什么

示例代码: 这只是苹果的位置教程(带ARC)

然后改变:

  • (void)ApplicationIDFinishLaunching:(UIApplication*)应用程序{}
为了

并将@interface LocationAppDelegate…@替换为

@interface LocationsAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    UITabBarController *tabBarController;

    NSPersistentStoreCoordinator *persistentStoreCoordinator;
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;       
}

@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) UITabBarController *tabBarController;

- (IBAction)saveAction:sender;

@property (nonatomic, strong, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, strong, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

@property (weak, nonatomic, readonly) NSString *applicationDocumentsDirectory;

@end
@接口位置代理:NSObject{
UIWindow*窗口;
UITabBarController*tabBarController;
NSPersistentStoreCoordinator*persistentStoreCoordinator;
NSManagedObjectModel*managedObjectModel;
NSManagedObjectContext*managedObjectContext;
}
@属性(非原子,强)IBUIWindow*window;
@属性(非原子,强)UITabBarController*tabBarController;
-(IBAction)保存操作:发送方;
@属性(非原子、强、只读)NSManagedObjectModel*managedObjectModel;
@属性(非原子、强、只读)NSManagedObjectContext*managedObjectContext;
@属性(非原子、强、只读)NSPersistentStoreCoordinator*persistentStoreCoordinator;
@属性(弱、非原子、只读)NSString*applicationDocumentsDirectory;
@结束

编译并运行。

尝试摆脱
[windowaddsubview:self.tabBarController.view]

即使尝试此NSArray*TwoViewController=[[NSArray alloc]initWithObjects:self.firstNav,self.anotherNav,nil],是否也会出现相同的问题;是的,同样的问题。第一个导航转到第一个选项卡,显示良好,但无法选择第二个选项卡。由于某种原因,这第二个标签对触摸事件没有响应。你能把项目转发给我吗,因为代码似乎没问题。嗨,谢谢!由于无法发送私人消息,我不太确定将其发送到何处,因此我添加了一些关于如何复制此行为的更多信息。。你可以在这里尝试,将电子邮件设置为和从电子邮件设置为你的个人电子邮件id。将生成一个链接,你可以将其粘贴到这里
@interface LocationsAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;

    UITabBarController *tabBarController;

    NSPersistentStoreCoordinator *persistentStoreCoordinator;
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;       
}

@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) UITabBarController *tabBarController;

- (IBAction)saveAction:sender;

@property (nonatomic, strong, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, strong, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, strong, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

@property (weak, nonatomic, readonly) NSString *applicationDocumentsDirectory;

@end