2013-11-28 90 views
0

我有一个嵌入在标签栏中的主实用程序应用程序。现在,对于这个标签栏,我有以下内容。标签栏元素onclick IOS

@interface MainTabViewController : UITabBarController< UITabBarControllerDelegate>{ 
} 
@end 

@implementation MainTabViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
    } 
    return self; 
} 
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ 
    NSLog(@"One"); 
    if(self.tabBarController.selectedIndex==1) 
    { 
     NSLog(@"clicked"); 
    } 

    if (self.tabBarController.selectedIndex==2) { 
     NSLog(@"Helo"); 
    } 
} 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.tabBarController.delegate = self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

@end 

该代码根本没有达到didSelectViewController。我是IOS新手。任何人都可以指导我哪里错了?

+0

请出示了代码你在哪里添加MainTabViewController在你的应用程序窗口中。 –

回答

2

添加委托方法给的UITabBarController

或者使用故事板(如果您使用)

或者不如说是的UITabBarController不要使用

self.delegate = self ; 
+0

感谢队友,它工作! – bharath