ios - Why my ViewDidLoad Loads every time? -


i creating app in implemented fb login. write fblogin button code in viewdidload in viewcontroller.m file.

- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib.  fbsdkloginbutton *loginbutton = [[fbsdkloginbutton alloc] init]; loginbutton.center = self.view.center; [self.view addsubview:loginbutton];  } 

but when ran code. fb buttons appears in pages of app, means viewcontroller.m viewdidload method call every time.why? looking solution last 4 hours didnt result yet. please me out.

as you've said, view controllers inherit view controller, every view controller calls [super viewdidload] execute method. (the solution isn't removal of super call).

instead of creating viewcontroller , every other view controller inherit 1 could:

  • create commonviewcontroller implements common between view controllers
  • create facebookloginviewcontroller inherit commonviewcontroller.

thus, inheritance tree like:

commonviewcontroller       /          \      /            \     /              \ facebookloginvc    otherviewcontrollers 

instead of:

viewcontroller (which equivalent facebookviewcontroller)      |      |      | otherviewcontrollers 

Comments