方法如何告诉哪个视图控制器调用它 [英] How can a method tell which view controller called it

查看:119
本文介绍了方法如何告诉哪个视图控制器调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用自己的方法获取当前的视图控制器。我的意思是我有两个视图控制器调用相同的方法。因为我想分散视图控制器类正在调用该方法。

I want to get the current view controller in my own method. I mean i have two view controllers which are calling a same method. In that i want to diffentiate from which view controller class is calling that method.

请帮帮我

推荐答案

让我们说 myCommonMethod:是从视图控制器调用的常用函数,你可以检查你的 viewController 使用 isMemberOfClass: NSObject 的方法是否是类的成员。

Lets say myCommonMethod: is the common function called from both the view controller , you could check your viewController whether it's the member of a class or not using isMemberOfClass: method of NSObject.

-(void) myCommonMethod:(UIViewController*) aViewController
{
      if([aViewController isMemberOfClass:NSClassFromString(@"MyFirstController")])
      {
      }
      else if([aViewController isMemberOfClass:NSClassFromString(@"MySecondController")])
      {  

      }
}

这篇关于方法如何告诉哪个视图控制器调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆