ios - 获取 TableView 的 CustomCell 中的 UIViewController

标签 ios objective-c uitableview

我有一个 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/

相关文章:

ios - 无效更新 : invalid number of items on UICollectionView

ios - 未加载来自 segue 的 UIPickerView 项目

iphone - 将 UITabBarController 添加到 UIViewController

objective-c - UIView 子类 : performSelecter:withDelay: say 5 secs but the view is removed at 3rd sec?

iphone - UITableView 的本地化索引

ios - 自定义tableview滚动效果,如google底漆

ios - 如何获取所有已安装路由应用程序的列表?

ios - 奇怪的 iPad 旋转效果

ios - UITableView - 在 vi​​ewDidAppear 之前滚动到底部

ios - 在 iOS 应用程序中计算 G - Force