导航栏和底部工具栏不工作(不响应tap/click)

The navigation bar and bottom toolbar is not working(not respond to tap/click)

我在ios7(ipad)中遇到了一个问题,就是导航栏和底部工具栏无法捕捉到点击事件。相同的代码在 ios 8 (iphone/ipad) 中运行良好。这是我的代码,我有一个 slideView,它是一个 UIView,我将另一个 UIView singleCamView 推入其中。第一次加载到singleCamView时,导航和工具栏不起作用,但是当我返回slideView并再次进入singleCamView时,一切正常。

在幻灯片视图中:

(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self changeUILayout];
    [serverMgr disableTalkFunc];
    if (eLayoutType == eLayout_1X1 && !backFrom1x1) {
        [self changeLayout_1x1];
    }
}

(void)changeLayout_1x1 {
    if ([self.navigationController.visibleViewController isKindOfClass:[SlideView class]]) {
        int camInArray = 0;//iPageIdx * [self getPreviewNum] + singleCamPos;

        SinglePageViewController_Base *firstPage = [viewControllers objectAtIndex:0];
        SingleCamViewController * mCam = [[SingleCamViewController alloc] initWithServerManager:serverMgr CurrentCam:camInArray];
        [mCam setParent:firstPage];
        [mCam setTitle:[serverMgr getDeviceNameByChIndex:0]];
        mCam.changeLayoutDelegate = self;
        int ch_index = 0;//iPageIdx * [self getPreviewNum] + pos;
        [serverMgr updateAudioAndPtzDeviceByChIndex:ch_index];
        [mCam setPtzCap:[serverMgr isSupportPTZ:ch_index]];
        [mCam setAudioCap:[serverMgr isSupportAudio:ch_index]];
        [mCam setTalkCap:[serverMgr isSupportTalk:ch_index]];
        [firstPage setSingleCam:mCam];
        [serverMgr setPlaybackDelegate:mCam];
        [self.navigationController pushViewController:mCam animated:YES];
        //clear to default picture
        [firstPage setDefaultPic];
        [serverMgr disconnectAllCam];
        [serverMgr connectToCamWithHighResolution:ch_index];
        [mCam release];

        eLayoutType = eLayout_1X1;
        [serverMgr setLayoutType:eLayout_1X1];
        [parent save];
    }
    else {
        return;
    }
}

在单摄像头视图中:

....
UIImage *backImage;
UIButton *bButton = [UIButton buttonWithType:UIButtonTypeCustom];
if (IS_IPAD)
    backImage = [UIImage imageNamed:@"Back_48x48_nor.png"];
else
    backImage = [UIImage imageNamed:@"Back_32x32_nor.png"];
bButton.bounds = CGRectMake(0, 0, backImage.size.width, backImage.size.height);
[bButton setImage:backImage forState:UIControlStateNormal];
[bButton addTarget:self action:@selector(onBackBtnTap) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * backButton = [[UIBarButtonItem alloc] initWithCustomView:bButton];
UIBarButtonItem * backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackBtnTap)];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [backButton setTintColor:COLOR_NAVBUTTONTINT];
}
else {
    [backButton setTintColor:COLOR_NAVBUTTONTINTIOS6];
}
self.navigationItem.leftBarButtonItem = backButton;
[backButton release];

重要的是,它在ios8 中运行良好,我无法弄清楚原因。谢谢。

终于解决了我自己的问题,这里是解决方案,关键是第二个视图是在主视图创建后立即推送的,控制器(可能)还没有完全初始化。所以我在主视图和第二视图之间添加了一个延迟,一切正常。

这个 post 给了我解决方案。 Adding delay between execution of two following lines