Can't add self as subview的問(wèn)題

原因一:加入了本身的視圖

[self.view addSubview:self.view];

原因二:重復(fù)推出了控制器
下面的方法能復(fù)現(xiàn)bug

[self.navigationController pushViewController:set animated:YES];
    //0.3秒后重復(fù)推出(正常是0.5)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.navigationController pushViewController:set animated:YES];
    });

解決:
1.Commond + N 新建Objective-C File文件


張小牛.png

2.UINavigationController+ZXN中添加如下代碼

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated isFixed:(id)isFixed{
    if (!isFixed || self.topViewController == isFixed){
        [self pushViewController:viewController animated:animated];
    }
}

- (id)navigationlock{
    return self.topViewController;
}

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated isFixed:(id)isFixed{
    if (!isFixed || self.topViewController == isFixed){
        [self popToViewController:viewController animated:animated];
    }
    return nil;
}

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated navigationLock:(id)isFixed{
    if (!isFixed || self.topViewController == isFixed) {
        [self popToRootViewControllerAnimated:animated];
    }
    return nil;
}

3.用法

id isFixed = [self.navigationController isFixed];
[self.navigationController pushViewController:compet animated:YES isFixed: isFixed];

4.檢驗(yàn)

 id isFixed = [self.navigationController isFixed];
[self.navigationController pushViewController:compet animated:YES isFixed: isFixed];
    //0.3秒后重復(fù)推出(正常是0.5)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       [self.navigationController pushViewController:compet animated:YES isFixed: isFixed];
 });
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容