ViewWillAppear vs Viewdidload ios

When using the code with the iOS navigation application, I ran into a problem:

Where can I put the "initdata" method for a UITableView? in viewWillAppear or viewDidLoad?

please help me.

+7
source share
2 answers

You can put initData according to your application requirement,

if your table needs to load data with new data every time, then it should be under

- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; //initData } 

Otherwise, if the table needs to be reloaded with one Data that does not change or there is not any editing operation performed in Data, you should use

 - (void)viewDidLoad { [super viewDidLoad]; //initData } 
+14
source

It’s better to call it in the initWithNibName:bundle: or initWithCoder: and free uploaded data in -(void)dealloc .

Alternatively, you can have this in viewDidLoad and free uploaded data in viewDidUnload . But it’s better not to call it from viewWillAppear:

Edit:

I hope this array depends on the selection in the parent view. In this case, write the setter method, which sets the condition and initializes the data before pressing the view controller.

 DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; // Pass the selected object to the new view controller and depend on that, load the data. [detailViewController initData:(id)[_list objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; 
+2
source

All Articles