我有一个 UIViewController
命名为“MainView”,其中有一个 UITableView
命名为“tblLists”tblLists
生成customCell
- “自定义单元列表”。
我的问题是我能得到 MainView
customCellList
中的实例(自身)类(class)。
我尝试了 superview 的东西,但没有得到 MainView
.我想在没有协议(protocol)的情况下实现这一点。
所以需要你的帮助。
最佳答案
您可以使用响应者链来访问 View Controller 。假设您的 customCell 类是 UITableViewCell 子类,以下方法应该可以完成这项工作:
@implementation customCell
- (UIViewController *)getViewController
{
id vc = [self nextResponder];
while(![vc isKindOfClass:[UIViewController class]] && vc!=nil)
{
vc = [vc nextResponder];
}
return vc;
}
@end
以上代码由 Sensible TableView 提供框架。
关于ios - 获取 TableView 的 CustomCell 中的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15562732/