在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;
}```