我想知道 tabbar 中将选择哪个项目。我添加了以下 UITabBarController appdeletegate.m 文件。标签项目栏显示正确。在我选择项目后,我想知道将选择哪个项目。
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];
直径控制器.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 为 do 选择项添加了以下方法。但它不起作用。我如何以及在哪里不能写然后得到选定的项目?
- (void)tabController:(UITabBarController *)tabController didSelectViewController:(UIViewController *)viewController
{
UINavigationController *navigationController = (UINavigationController *)viewController;
[navigationController popToRootViewControllerAnimated:NO];
}