iOS6
Xcode 4.5.1
Making application for iOS5 or later
using storyboard
我想在单击 tabBarItem 时加载 URL。
在targetViewController.m
@interface targetViewController ()
@end
@implementation targetViewController
@synthesize webview;
- (void)viewDidLoad
{
[self loadingMethod:view.webview];
[super viewDidLoad];
}
(snip)
并且target2ViewController.m几乎与targetViewController.m相同
在customTabBarViewController.m
- (void)tabBar:(UITabBar*)tabBar didSelectItem:(UITabBarItem*)item {
NSString *str;
if(item.tag == 0) {
webview = ((targetViewController *)self.selectedViewController).webview;
[self myLoadingMethod:webview];
} else if (item.tag == 1){
webview = ((target2ViewController *)self.selectedViewController).webview;
[self myLoadingMethod:webview];
}
}
但是这效果并不好。 当单击 targetViewContoller 的 tarBarItem 时,将加载目标“2”ViewContoller 的 webview。 单击目标“2”ViewCOntroller 的 tabBarItem,将加载 targetViewContoller 的 webview。
那么我如何访问包含在 ViewController 中的 clited tabBarItem 中的 webview?
最佳答案
使用UITabBarController
属性selectedViewController
,这将为您提供选定的ViewController
。
在代码中添加 [self myLoadingMethod:wwebview]
;这是错误的,应该是[self myLoadingMethod:webview]。请检查。
关于iphone - 如何访问在TabBarViewController中选择的ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13136335/