检测所选 UITabbarItem 上的重新选项卡 [英] Detect a re-tab on selected UITabbarItem

查看:26
本文介绍了检测所选 UITabbarItem 上的重新选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测所选 UITabbarItem 上的重新标签.我正在使用 UIWebview,在 UITabbar 中索引 1 处的主页按钮上重新设置标签后,该网址需要再次重置为主页.

I'm trying to detect a re-tab on the selected UITabbarItem. I'm using a UIWebview which url needs to be reset to the homepage again after re-tab on the Home button at index 1 in the UITabbar.

问题是:我正在使用故事板并尝试使 UITabbar 委托,但它不起作用.

Problem is: I'm using a storyboard and tried to make the UITabbar delegate, but it's not working.

AppDelegate.h:

AppDelegate.h:

#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

didLaunchWithOptions:

didLaunchWithOptions:

UITabBarController *tabController =
(UITabBarController *)self.window.rootViewController;
tabController.selectedIndex = [defaults integerForKey:kOptionLastTabSelectedKey];
tabController.delegate = self;

它给出了以下错误:

AppDelegate.m:26:36: Use of undeclared identifier 'defaults'

然后我需要检测该选项卡是否已被重新标记,如果是,则必须将 UI webview 重置为主页.那么有人建议如何检测特定选项卡上的重新选项卡吗?它位于索引 1.

Then I need to detect if the tab has been re-tabbed, and if so, the UI webview must been reset to the homepage. So anyone a suggestion how to detect a re-tab on a specific tab? It's at index 1.

我试过了:

- (void)tabController:(UITabBarController*)tabController didSelectViewController:(UIViewController*)viewController
{

    if (tabController.selectedViewController == viewController)
    {
        tabController.selectedIndex =0;
    }
}

推荐答案

首先设置 userdefaults,然后像下面这样尝试:-

First set userdefaults and then try like this below:-

NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
tabController.selectedIndex = [defaults integerForKey:kOptionLastTabSelectedKey];

这篇关于检测所选 UITabbarItem 上的重新选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆