我有一个具有4个选项卡的TabBarControllers应用程序。现在,在didFinishLaunchingWithOptions我这样做:获取ViewController的名称
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 5.0;
lpgr.delegate = self;
[self.window addGestureRecognizer:lpgr];
[lpgr release];
这部分工作,并长按手势是在所有的四个选项卡识别。现在,我想传递用户当前正在按下的当前ViewController的名称,以便我可以将其传递到处理长按事件的函数中。
但这只会返回AppDelegate类而不是ViewController类。我想在appDelegate中做所有事情,而不是在每个ViewController中放入NSStringFromClass([self class])。 – Diffy 2012-03-02 04:53:42
@Diffy看下面一个... !!!! – Kamarshad 2012-03-02 05:06:46
@Diffy您可以为选项卡VC中的每个VC创建公共方法(例如'selectedViewControllerName:'),然后可以调用所选VC的方法来获取VC的正确名称。 _“我想在appDelegate中做所有事情,而不是在每个ViewController中放置NSStringFromClass([self class]),如果是这样,只需使用第一个ViewController,就可以通过选中VC的TAG来返回名称。 – Kjuly 2012-03-02 05:51:59