#pragma remark -tableviewCell 上级控制器 (可以放到公共方法类中 方便调用)
+(UIViewController *)viewController:(UIView *)view
{
UIResponder *next = [viewnextResponder];
do {
if ([nextisKindOfClass:[UIViewControllerclass]]) {
return (UIViewController *)next;
}
next = [next nextResponder];
} while (next !=nil);
returnnil;
}
//cell里面直接调用viewController 获取控制器
PictureViewController *pic =[[PictureViewControlleralloc] init];
// 对模式对话框 弹出view
[[UIUtilsviewController:self]presentViewController:pic
animated:YES
completion:nil];
//或者 push
[[UIUtilsviewController:self].navigationControllerpushViewController:pic animated:YES]
本文介绍了一种在iOS开发中获取UIViewController实例的通用方法,通过遍历视图层级,该方法可以在不需要直接引用控制器的情况下获取到所需的ViewController。此外,还展示了如何在cell中调用此方法,并演示了如何使用该方法创建并展示模式对话框或进行导航操作。
1360

被折叠的 条评论
为什么被折叠?



