TabBarController isKindOfClass - UINavigationController 的问题
我有一个带有 ViewController 的 TabBar。我在我的 AppDelegate 中执行此操作。所以我有一个 UINavigationController
test1ViewController = [[Test1ViewController alloc] init];
test2ViewController = [[Test2ViewController alloc] init];
test3ViewController = [[Test3ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: test2ViewController];
NSArray* controllers = [NSArray arrayWithObjects: test1ViewController, navigationController, test3ViewController, nil];
[self.tabBarController setViewControllers:controllers animated:YES];
[navigationController release];
现在我遇到了这一行源代码的问题:
[(Test2ViewController *)[appDelegate.myTabBarController selectedViewController] methodName:arg1 withTag:arg2];
这里会有一个 SIGBRT,因为 selectedViewController 在这种情况下是一个“UINavigationController”。但我想调用“Test2ViewController”的方法。我怎么能这样做呢? 通常我也会这样做:
if([[appDelegate.myTabBarController selectedViewController] isKindOfClass:[Test2ViewController class]]) { ... }
但这也会失败,因为它是一个 UINavigationController。如何解决这个问题?有谁知道吗?
预先非常感谢&此致。
I have a TabBar with ViewController in it. I do this in my AppDelegate. So I have one UINavigationController
test1ViewController = [[Test1ViewController alloc] init];
test2ViewController = [[Test2ViewController alloc] init];
test3ViewController = [[Test3ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: test2ViewController];
NSArray* controllers = [NSArray arrayWithObjects: test1ViewController, navigationController, test3ViewController, nil];
[self.tabBarController setViewControllers:controllers animated:YES];
[navigationController release];
Now I have the problem with this line of source code:
[(Test2ViewController *)[appDelegate.myTabBarController selectedViewController] methodName:arg1 withTag:arg2];
Here there will be a SIGBRT, because the selectedViewController is in this case an "UINavigationController". But I want to call a method of the "Test2ViewController". How could I do this?
Normally I also do this:
if([[appDelegate.myTabBarController selectedViewController] isKindOfClass:[Test2ViewController class]]) { ... }
But this also fail because it is a UINavigationController. How to fix that? Does anyone know?
Thanks a lot in advance & Best Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试以下操作:
Try the following: