Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ios中选择tab时如何在AppDelegate中重新加载webview_Ios - Fatal编程技术网

在ios中选择tab时如何在AppDelegate中重新加载webview

在ios中选择tab时如何在AppDelegate中重新加载webview,ios,Ios,我是iOs开发新手,我不能解决这个问题 选择UIAB时如何重新加载uiwebview以下是我的代码: - (void)tabBarController:(UITabBarController *)aTabBarController didSelectViewController:(UIViewController *)viewController { if(self.tabBarController.selectedIndex == 0) { [[NSURLCa

我是iOs开发新手,我不能解决这个问题 选择UIAB时如何重新加载uiwebview以下是我的代码:

- (void)tabBarController:(UITabBarController *)aTabBarController didSelectViewController:(UIViewController *)viewController
{

    if(self.tabBarController.selectedIndex == 0)
    {
        [[NSURLCache sharedURLCache] removeAllCachedResponses];

        BSHomeViewController *homeViewController = [[BSHomeViewController alloc] initWithNibName:nil bundle:nil];
        BSHomeViewController.webView = nil;

        [BSHomeViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:HOMEPAGE]]];


    }
    [[NSUserDefaults standardUserDefaults] setInteger:self.tabBarController.selectedIndex forKey:@"BSSelectedTab"];
}
我在appdelegate中声明它,但它不会重新加载


请帮我解决这个问题。非常感谢您的回答。

您需要将AppDelegate设置为tabbarcontroller的委托

您可以在didFinishLaunchingWithOptions中执行此操作

self.tabBarController.delegate = self;
我不确定这是否是正确的设计


为什么不在BSHomeViewController的ViewDidDisplay中重新加载webview?

调用
BSHomeViewController*homeViewController=[[BSHomeViewController alloc]initWithNibName:nil bundle:nil]时,上面的代码正在实例化BSHomeViewController的新实例并且该视图永远不会显示或推送给用户查看。当UITabBar切换到所选的ViewController时,是否存在不选择利用ViewWillDisplay或ViewDidDisplay的原因

编辑:这是丑陋的,但它会工作

TabBarDelegate.m

- (void)tabBarController:(UITabBarController *)aTabBarController didSelectViewController:(UIViewController *)viewController
{

    if(self.tabBarController.selectedIndex == 0)
    {
            [viewController viewWillAppear:YES];
    }
    [[NSUserDefaults standardUserDefaults] setInteger:self.tabBarController.selectedIndex forKey:@"BSSelectedTab"];
}
BSHomeViewController.m

- (void)viewWillAppear:(BOOL)animated 
{
    [super viewWillAppear:animated];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:HOMEPAGE]]];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:HOMEPAGE]]];
}

每次显示BSHomeViewController的视图时重新加载webview

在您的BSHomeViewController.m中

- (void)viewWillAppear:(BOOL)animated 
{
    [super viewWillAppear:animated];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:HOMEPAGE]]];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:HOMEPAGE]]];
}

您的网络视图位于哪里?在哪个视图控制器中?另外,他将nil分配给webview,然后要求加载请求谢谢,这是一个很大的帮助,我很高兴它起了作用。有一些更优雅的方法可以做到这一点,但如果你能与快速和肮脏的生活,它将工作。感谢您的待定解决方案复选标记。祝你好运谢谢你的帮助,但我已经做到了,我需要在每次点击uitab时重新加载它,例如,当我在“主页”选项卡中时,当我再次点击它时,它应该再次在同一选项卡上重新加载。你已经做了什么?设置代理?或者在ViewDidDisplay中重新加载?代码中的另一个相关错误:web视图为零,无法向其发送消息。