0

我正在尝试检测所选UITabbarItem. 我正在使用UIWebview需要在 UITabbar 中索引 1 处的主页按钮上重新选项卡后再次将哪个 url 重置为主页。

问题是:我正在使用情节提要并尝试制作UITabbar委托,但它不起作用。

AppDelegate.h:

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

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。

我试过了:

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

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

1 回答 1

1

首先设置 userdefaults 然后尝试如下: -

NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
tabController.selectedIndex = [defaults integerForKey:kOptionLastTabSelectedKey];
于 2013-10-24T10:22:48.583 回答