UICollectionView的頭部添加按鈕后,無法使用pushViewController跳轉(zhuǎn),解決方法

UICollectionView的頭部中添加了一個(gè)按鈕,想通過點(diǎn)擊按鈕跳轉(zhuǎn)到另一個(gè)控制器,但是在UICollectionView的頭部中無法使用[self.navigationController pushViewController:p animated:YES]這個(gè)方法跳轉(zhuǎn),求教了大牛后給出來解決方案:


把下面的代碼當(dāng)做category放到你的項(xiàng)目中。

view里面,可以通過,[self.viewController.navigationController pushViewController:p animated:YES]進(jìn)行跳轉(zhuǎn)。

//獲取某個(gè)view所在的控制器
- (UIViewController *)viewController { 
    UIViewController *viewController = nil; 
    UIResponder *next = self.nextResponder; 
    while (next) {  
       if ([next isKindOfClass:[UIViewController class]]) { 
           viewController = (UIViewController *)next; 
           break; 
        } 
    next = next.nextResponder; 
    } 
    return viewController;
}```
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容