简体   繁体   中英

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

I have a problem in ios7(ipad), that is, the navigation bar and the bottom toolbar can not catch the tap event. The same code works fine in the ios 8 (iphone/ipad). Here is my code, I have a slideView which is a UIView, and I push another UIView singleCamView into it. The first time I load into the singleCamView, the navigation and the toolbar isn't working, but when I go back to slideView and get into the singleCamView again, everything is fine.

In slideView:

(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;
    }
}

In singleCamView:

....
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];

The important thing is, it works fine in ios8, I can't figure out the reason. Thank you.

Finally I solve my own problem, here is the solution, the key point is that the second view is pushed right after the main view is created, the controller (maybe) is not fully initialized yet. So I add a delay between main view and second, everything works fine.

This post gives me the solution. Adding delay between execution of two following lines

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM