【发布时间】:2023-04-05 12:44:01
【问题描述】:
我有一个带有 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。如何解决?有人知道吗?
非常感谢提前和最好的问候。
【问题讨论】:
标签: iphone uinavigationcontroller uitabbarcontroller