Lama
Lama

Reputation: 255

viewdidappear is not called from tab bar controller

I have a TabBarController with NavigationController... the main TabController has some buttons which i want to add borders to... am doing this in ViewDidAppear but its not called! when i go to child controller and click back button its called now .. but when firstly click the tab is not called!

and what am doing is this in the main tab vc:

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if MOLHLanguage.isArabic(){
        aboutusbtn.addRightBorderHome( borderWidth: 3)
        rulesbtn.addRightBorderAboutus(borderWidth: 3)
        committeebtn.addRightBorderHistory(borderWidth: 3)
        generalbtn.addRightBorderShare(borderWidth: 3)
        publickbtn.addRightBorderHome(borderWidth: 3)
        contactusbtn.addRightBorderAboutus(borderWidth: 3)
    }else{
        aboutusbtn.addLeftBorderHome(width: 3)
        committeebtn.addLeftBorderAboutus(width: 3)
        rulesbtn.addLeftBorderHistory(width: 3)
        generalbtn.addLeftBorderShare(width: 3)
        publickbtn.addLeftBorderHome(width: 3)
        contactusbtn.addLeftBorderAboutus(width: 3)
    }
}

but this is not called until i click back from child ... but when first click on the tab it will not be called!

why? and how to solve this?

Upvotes: 2

Views: 2238

Answers (2)

Lama
Lama

Reputation: 255

I have found the solution ..

I just added the following:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
 }

In the navigation controller, and it was solved! :)

Upvotes: 2

Naresh
Naresh

Reputation: 955

I have also faced this issue many times, Make sure you are not calling any wrong super class method in child class i.e. For example, in your viewWillAppear you'r not calling the viewDidAppear method. or vice-versa. This is compilers undefined behaviour. It mostly occurs in parent child view_controller's hierarchy.

For your solution, you can execute the code with small delay from viewWillAppear.

Upvotes: 1

Related Questions