开发者

Which tab controller is the one being picked?

I have a tab bar controller with five buttons. That controller has a tab view controller.

The tab view controller should behave differently depending on the tab being pressed.

For example, if the tab is "location", then the displayed data should be sorted based on location. If the tab is "alphabet", then the view should be sorted based on the alphabet.

I have this code in the view controller

-(void)viewWillAppear:(BOOL)animated
{
    [super viewDidLoad];
    [BNUtilitiesQuick parseXMLFileAtURL:@"http://example.com/BusinessSerialized.xml"];
    [BNUti开发者_Python百科litiesQuick UtilitiesQuick].BizsToDisplay = [BNUtilitiesQuick searchObjectsInContext:@"Business" :nil :@"Title" :YES];
    NSLog(@"%@",[self tabBarController]);
    if ([[self tabBarController]selectedIndex]==0)
    {
    }
    NSLog(@"%d",[[self tabBarController] selectedIndex]);

    // Do any additional setup after loading the view from its nib.
}

That [[self tabBarController] selectedIndex] works, except for one problem. Rather than giving the current selected index, it's the previous index.

Say I am now selecting tab 0, and I click tab 4; that NSLog() will display 0.

How can I solve this? I want to know the tab being pressed.


By using this delegate method you will be getting your selected index:

# enter code here
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"sff %d",tabBarController.selectedIndex);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜