0
我想知道在tabbar中選擇哪個項目。我添加了以下UITabBarController appdeletegate.m文件。標籤項目欄正確顯示。當我選擇了我想知道哪個項目將選擇的項目後。UITabBarController委託didselect項目
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.m我已經添加了以下方法做了選擇項。但它不工作。如何和在哪裏我不能寫,然後得到選定的項目?
- (void)tabController:(UITabBarController *)tabController didSelectViewController:(UIViewController *)viewController
{
UINavigationController *navigationController = (UINavigationController *)viewController;
[navigationController popToRootViewControllerAnimated:NO];
}
感謝它現在的工作 – vijay