0

I have UITableViewController where I need to put initialization code only once to populate data source. in which method to put this code.

I tried with viewWillAppear: method, but it get executed every time view appear.

Andrey Zverev
  • 4,409
  • 1
  • 28
  • 34
user836026
  • 10,608
  • 15
  • 73
  • 129

3 Answers3

1

if you want to display things only once that the View has comed on screen, then yeah. go for it. Otherwise you also have ViewdidLoad or ViewWillAppear if you have to arrange things before the view begins the transition to slide in.

All of these methods will be executed every time from the tableView you tap on a row.

anyway the pattern you are trying to achieve is called singleton, you can find out about it more over here

What should my Objective-C singleton look like?

Community
  • 1
  • 1
holographix
  • 2,497
  • 2
  • 32
  • 46
0

You can put it in viewDidLoad and it will be only once.

shannoga
  • 19,649
  • 20
  • 104
  • 169
0

The - (void)viewDidLoad method is probably the place you want use. It gets called once the view controller has finished doing its loading code (either by loading a XIB or by calling loadView).

DarkDust
  • 90,870
  • 19
  • 190
  • 224