开发者社区> 问答> 正文

根据id获取viewcontroller名称

从 id 获取 viewcontroller 名称,并且使用id调用获取的类方法。
代码:

UIViewController *view = (UIViewController*)self.objCurentCallLocation;
[view LocationCalledAndReturned];

展开
收起
爵霸 2016-03-17 11:46:54 2005 0
1 条回答
写回答
取消 提交回答
  • 可以通过下面的代码来判断这个id类型是不是你想要的控制器

    UIViewController *viewController = (UIViewController*)self.objCurentCallLocation;
    if ([viewController isKindOfClass:[TestViewController class]]) {
           [((TestViewController *)viewController)  callMethodUnderTestViewController];
    }

    上面的代码中,假设了一个已存在的TestViewController。判断你当前拿到的这个viewController是TestViewController,如果是,则隐式转换,并调用TestViewController中的pulic方法

    2019-07-17 19:05:01
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载