【iOS解决思路】得到某个view所在的ViewController
2024-10-14 02:46:33
在一个tableViewCell中有个btn,如何得到它所在的viewcontroller,以便于push出新的viewController?
我的思路是传值,但网上有下面这种方法,分享。
跟得到某个视图上的子视图思想类似,但之前没有接触过 UIResponder,所以没有想到。
- (UIViewController *)viewController {
for (UIView* next = [self superview]; next; next =
next.superview) {
UIResponder* nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {return (UIViewController*)nextResponder;
}
}
return nil;
}
最新文章
- 解析大型.NET ERP系统 查找与钻取
- Dynamics AX 2012 R2 通过数据源保存记录时触发的方法
- Delphi指针的用法
- GET和POST的主要区别
- C# - openxml 操作excel - '“System.IO.Packaging.Package”在未被引用的程序集中定义'
- ubuntu14.04 Markdown编辑器推荐之Remarkable
- 51nod 1686 第k大区间
- SLAM+语音机器人DIY系列:(一)Linux基础——3.Linux命令行基础操作
- javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
- Nginx、haproxy反向代理设置
- 详解 ESLint 规则,规范你的代码
- ASP.NET匿名对象与集合的使用
- C++中cin的用法汇总
- C语言学生管理系统源码分享
- git命令上传项目到码云总结
- python 输出所有列表元素的乘积
- GitHub Permission to <;<;repository>;>; denied to <;<;username>;>;
- java.util.concurrent.Semaphore 使用
- 当集合里存储的是URL时的一些问题总结
- BNU 20860——Forwarding Emails——————【强连通图缩点+记忆化搜索】
热门文章
- 给出2n+1个数,其中有2n个数出现过两次,如何用最简便的方法找出里面只出现了一次的那个数(转载)
- javascript 常用array类型方法
- How to scroll the window using JQuery $.scrollTo() function
- window 7 C盘整理
- VBox UUID already exists 问题处理
- 原创 HTML5:JS操作SVG实践体会
- select options常用操作
- [Python笔记]第二篇:运算符、基本数据类型
- Python三元表达式
- asp.net(C#)写SQL语句技巧