objective-c - 在 tabBarController 中的 UIViewController 上调用实例方法

标签 objective-c ios ios5

我通过 XCode 4.5.1 中的模板创建了一个简单的 Tab Bar 应用程序,它在 app_delegate 中为我提供了两个像这样的 View Controller :

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;

在 viewController1 中,我有一个写出一些登录/注销按钮的实例方法。其中一个回调在 app_delegate 中,想调用 viewController1 中的实例方法。我试过这个:

[[self.tabBarController.viewControllers objectAtIndex:0 ] renderButton];

但它不起作用。这种类型的查询是可能的还是我应该使用其他技术?

提前谢谢

最佳答案

你写的应该有用。强制转换不是必需的(尽管它确实使代码更具可读性)。如果您确定 renderButton 没有被调用(在此方法中放置断点或 NSLog 消息),我猜是您忘记在 FirstViewController 的头文件中声明它。

@interface FirstViewController : UIViewController
-(void)renderButton;
@end

关于objective-c - 在 tabBarController 中的 UIViewController 上调用实例方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13076362/

相关文章:

ios - 无法获取第一个单元格的正确索引

ios - Google Analytics 实时功能不起作用

ios - 计算准确的 Ibeacon 距离

ios - NSMutableArray始终转换为NSArray

ios5 - 使用 CaseInsensitiveCompare 的多个排序描述符对核心数据进行排序

objective-c - 为什么 Xcode 不建议 @synchronized?

ios - 类别+加载时间问题

iphone - 在 iOS 应用程序中对 Sqlite 的写访问

ios - 在同一台计算机上运行Xcode 4.01和4.2?

ios5 - 使用 autoresizingmask 的 UIView 水平居中不起作用