Search code examples
iosviewdidload

Why my ViewDidLoad Loads every time?


I am Creating a App in which I implemented FB login. So i write a FBLogin button code in my ViewDidLoad in ViewController.m file.

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];

}

but when i ran this code. fb buttons appears in all pages of my app, it means my viewController.m ViewDidLoad method call every time.Why? I am looking for solution last 4 hours but didnt get any result yet. please help me out.


Solution

  • Here is the Answer for my question

    I made a small mistake when i inherit all Other ViewControllers and main ViewController class with ViewController. i modified my code with

     @interface ViewController : UIViewController
    
    
     @end
    

    instead of

     @interface ViewController : ViewController
    
     @end
    

    and all other classes too like

       @interface homeViewController : UIViewController
    
       @interface contestViewController : UIViewController
    
    
       @interface menuViewController : UIViewController 
    

    etc.

    This simply solved my question. thanks for the help guys.