0

tabbar でどの項目が選択されるか知りたいです。次の UITabBarController appdeletegate.m ファイルを追加しました。タブ項目バーが正しく表示されました。ITEMを選択した後、どのアイテムが選択されるか知りたいです。

appDelegate.m

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,
                                               [UIFont fontWithName:@"TrajanPro-Regular" size:16],UITextAttributeFont, nil];


    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
    UIImage *navBackgroundImage = [UIImage imageNamed:@"top-bar.png"];
    [[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

    //BulletinViewController *bulletin = [[BulletinViewController alloc] initWithNibName:@"BulletinViewController" bundle:nil];
    //UINavigationController *bulletinNav =  [[UINavigationController alloc] initWithRootViewController:bulletin];
    //bulletinNav.navigationBar.barStyle = UIBarStyleBlack;

    CGFloat verticalOffset = 4;
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];

    DiaController *contact  = [[DiaController alloc] initWithNibName:@"DialerViewController" bundle:nil];
    UINavigationController *contactNav =  [[UINavigationController alloc] initWithRootViewController:contact];
    contactNav.navigationBar.barStyle = UIBarStyleBlack;


    ChViewController *chat  = [[ChatViewController alloc] initWithNibName:@"ChatViewController" bundle:nil];
    UINavigationController *chatNav =  [[UINavigationController alloc] initWithRootViewController:chat];





    //SettingsViewController *setting   = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
    //UINavigationController *settingNav =  [[UINavigationController alloc] initWithRootViewController:setting];

    self.tabController = [[UITabBarController alloc] init];
    CGRect tabframe = self.tabController.tabBar.frame;
    tabframe.origin.y -= 10;
    tabframe.size.height += 10;
    self.tabController.tabBar.frame = tabframe;
    self.tabController.delegate = self;
    self.tabController.viewControllers = @[contactNav,chatNav];
    UIImage *tabBackgroundImage = [UIImage imageNamed:@"bottom-bar.png"];
    [self.tabController.tabBar  setBackgroundImage:tabBackgroundImage];

    self.window.rootViewController = self.tabController;
    [self.window makeKeyAndVisible];

DiaController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        self.title = @"New";
        [[self tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"common_c.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"common_c.png"]];
        //[[self tabBarItem] setTitleTextAttributes:[[Common sharedInstance]getTabDict] forState:UIControlStateNormal];
    }
    return self;
}

ChViewController.m

     - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        self.title = @"New";
        [[self tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"common_c.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"common_c.png"]];
        //[[self tabBarItem] setTitleTextAttributes:[[Common sharedInstance]getTabDict] forState:UIControlStateNormal];
    }
    return self;
}

AppDelegate.mi は、did select 項目に対して次のメソッドを追加しました。しかし、うまくいきません。どのように、どこに書いて、選択したアイテムを取得できませんか?

- (void)tabController:(UITabBarController *)tabController didSelectViewController:(UIViewController *)viewController
{
        UINavigationController *navigationController = (UINavigationController *)viewController;
        [navigationController popToRootViewControllerAnimated:NO];

}
4

1 に答える 1