View will appear getting called twice in iOS 5



Currently i have solved one bug which was very much irritating for me so i thought to share it with you all.

Issue: My view will appear was getting called twice in iOS 5 due to which their was a twice call made to the web service resulting in duplication of data.

Solution:

What i had is a tab bar controller and to make a call to the viewWillAppear method in iOS 4 i made a use of the delegate method of the tab bar controller as per the UITabbarController protocol documentation



- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
     [viewController viewWillAppear:NO];
    
}


all was going well when suddenly my QA said to me that the duplication of data is still occuring, after a lot of research on this topic i made a quick fix here with of course a little advice from one of my friend and this is what i did


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    int osversion = [[[UIDevice currentDevice]systemVersion] intValue];
    
    if (osversion < 5
    {
         [viewController viewWillAppear:NO];
    }
}

Explanation: in iOS 4 the view will appear gets called only one time but i wanted a frequent call to this method hence i used the delegate method of the tab bar controller thinking that this could the solution but rather than solving the problem i increased it.

In iOS 5 their is no need to manually call or take help of any delegate method to make a call to the view will appear method so i made a small change in the delegate code and solved the issue and that was to check the system version and if its iOS 4 then only make a call to the view will appear method of the selected view controller from the delegate method of the tab bar controller.

This approach did the trick and solved the issue, and finally i don't have to see any duplicated data in my app anymore.


I solved the issue using the above method in case if you have any cool code that did the job for you would be glad if you could share the idea via comment or you may mail me to my mail id.


Until then happy iCoding and have a great day...

Comments

  1. Hey Radix

    I am using 10.7.2 and ios sdk 5.0 but viewwillappear working properly it get called just one time.

    ReplyDelete
  2. Ravi could you write following blogs i hope so it will be helpful for us.

    NewsStand
    ios 6 Features

    ReplyDelete
  3. Is this problem universal even in iOS6? I seem to have encountered such problem a few days ago.

    BTW, keep up the great work! I've added your blog to my blog roll.

    ReplyDelete

Post a Comment