iphone - 如何访问在TabBarViewController中选择的ViewController

标签 iphone objective-c ios ios5 ios6

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/

相关文章:

iphone - 使用音频队列播放和渲染流

ios - 如何使用 Pixate Framework 定义我的 CSS 以显示 'HelveticaNeue-Light'?

ios - NSTimer 没有触发选择器

ios - 当选择另一个单元格按钮时取消选择 Collection View 单元格按钮

iphone - 使用 iOS 进行 SMTP 发送的框架

ios - 限制用户在 TextView 中输入滥用词

iphone - "Full web"基于移动浏览器和屏幕大小的媒体查询

objective-c - cocoa touch 中的Javas Joda Time LocalDate类是什么?

ios - 创建可滑动的应用程序介绍屏幕

javascript - 当某个事件触发时,Javascript 可以在 iOS 中调用任何东西吗?