TabBarController isKindOfClass - UINavigationController 的问题

发布于 2024-08-16 17:20:39 字数 1160 浏览 2 评论 0原文

我有一个带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柳絮泡泡 2024-08-23 17:20:39

请尝试以下操作:

UINavigationController   *navController = (UINavigationController *) [appDelegate.myTabBarController selectedViewController];
Test2ViewController      *viewController = (Test2ViewController *) [[navController viewControllers] objectAtIndex: 0];

[viewController methodName:arg1 withTag:arg2];

Try the following:

UINavigationController   *navController = (UINavigationController *) [appDelegate.myTabBarController selectedViewController];
Test2ViewController      *viewController = (Test2ViewController *) [[navController viewControllers] objectAtIndex: 0];

[viewController methodName:arg1 withTag:arg2];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文