Reputation: 155
iOS6
Xcode 4.5.1
Making application for iOS5 or later
using storyboard
I want to load an URL when a tabBarItem is clicked.
At targetViewController.m
@interface targetViewController ()
@end
@implementation targetViewController
@synthesize webview;
- (void)viewDidLoad
{
[self loadingMethod:view.webview];
[super viewDidLoad];
}
(snip)
and target2ViewController.m is almost same as targetViewController.m
At 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];
}
}
However this doesn't work well. When the tarBarItem for targetViewContoller is clicked, the target"2"ViewContoller's webview will load. and the tabBarItem for target"2"ViewCOntroller is clicked, targetViewContoller's webview will load.
so How can I access to the webview which is included in the ViewController for the cliced tabBarItem?
Upvotes: 0
Views: 135
Reputation: 5060
Use UITabBarController
property selectedViewController
,which will give you the selected ViewController
.
In Code you adding [self myLoadingMethod:wwebview]
; which wrong and it should be [self myLoadingMethod:webview]. Please check.
Upvotes: 1