3

So i have a tab bar controller and when I select into the second tab it brings me to a table view controller. I have it setup so that when the viewWillAppear it animates the cells in. The problem I am having is that the first time I go into that view, everything is stationary, but if i go to another tab and come back, everything animates perfectly.

How can I get it to animate in the first time I go to the tab as well?

I have not included code because I do not think it will help answer the question.

Edit* I can go to the tab as many times as I want and it will animate each time, but will never animate on the first load of the app.

Dallas
  • 1,788
  • 2
  • 13
  • 24
  • the viewWillAppear will cal each time you go to that screen .As the each tab contains a navigation controller and each navigation controller contains viewcontrollers ... so form my point of view it should work fine. – sourav Mar 23 '16 at 05:49
  • @sourav That was my thoughts as well, but after testing on an iPhone, and the simulator, it works perfectly fine everytime I go to it, except the first time I go to it. – Dallas Mar 23 '16 at 05:50
  • set the delegate and datasource of tableView after viewdid load & reload the table after viewdidload . – sourav Mar 23 '16 at 05:57

2 Answers2

6

I had a very similar issue with viewDidAppear. My problem was that I called the viewDidAppear function in the TabBarController to do some stuff but forgot to call super.viewDidAppear(true) in this Method. Because of that the viewDidAppear of the child wasn't called. After I added it everything works like a charm.

So be sure to add super.viewDidAppear(true) or in your case super.viewWillAppear(true) in the TabBarController. Maybe it helps

inf1783
  • 944
  • 11
  • 12
1

I had the same issue. Tried the below in "ViewDidAppear" and it is working.

dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.tableView.reloadData()
        })
Saurabh_Jhingan
  • 190
  • 5
  • 20
  • That partially worked, the error I'm having with this is it shows the data for a fraction of a second unanimated, and then animates in. I fixed this by adding "tableView.hidden = true" in my viewDidLoad and then when calling the above in viewWillAppear i also inserted "tableView.hidden = false". With a little modification it worked like a charm, thanks a ton. – Dallas Mar 23 '16 at 05:58