0

I would like to know when we are setting setSelectedIndex for uitabbbarviewcontroller, Which delegate method will be called.

In my app, i have list of songs to purchase.when user taps buy button for any song, i will show the downloading tab.for that i am setting [self.tabBarController setSelectedIndex:3];there i am showing the song details and progressview that how much is downaloded etc.

This is fine upto this.in the meanwhile of downaloding poem the user can go and tap buy another poem. here i want to reload the tableview.but i dont know in which delegate method i should call reload data for tableview.

I tried viewwillappear and viewdidappear. but these are not called. So please tell me which delegate method will be called.

Thanks a lot

user198725878
  • 6,266
  • 18
  • 77
  • 135

2 Answers2

4

override UITabBarController setSelectedIndex:

-(void)setSelectedIndex:(NSUInteger)selectedIndex
{
    //must call super function. 
    [super setSelectedIndex:selectedIndex];

    [self myMethod];
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    [self myMethod];
}
user2142920
  • 231
  • 3
  • 5
1
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;

is called only when user taps it, when you programmatically set this, it is not called. You can fire a custom delegate method or notification as soon as you do it programmatically and do what ever you need to do...

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • why the heck delegate method is not called ? Any reason for that ? – yunas Mar 07 '13 at 16:31
  • well when you set it.. you can do whatever you want to do when the delgate method is called..so you can do it where you are programmatically setting it. – Ankit Srivastava Mar 07 '13 at 17:56
  • this is what I am saying it is not called. I have raised the query too kindly see this for more info http://stackoverflow.com/questions/15278537/why-does-selecting-a-tabbarcontroller-index-programatically-doesnt-call-delegate – yunas Mar 07 '13 at 18:06