Reputation: 401
When code with iOS navigation application, I have facing with trouble this:
where can I put the method "initdata" for UITableView? in viewWillAppear or viewDidLoad?
please help me out.
Upvotes: 8
Views: 12010
Reputation: 17478
It is better to call that in initWithNibName:bundle:
or initWithCoder:
method and release the loaded data in -(void)dealloc
.
Also, you can have that in viewDidLoad
and release the loaded data in viewDidUnload
. But it is better to avoid calling that from viewWillAppear:
Edit:
I hope that array is depending on the selection in the parent view. In that case, write a setter method, which sets the condition and init the data before pushing 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];
Upvotes: 2
Reputation: 4517
You can put initData as per your requirement of the app,
if your table needs to load data every time with new Data then it should be under
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//initData
}
Otherwise, if the table needs to be reload by a single Data which doesn't vary or there is not any editing operation performed on Data , you should use
- (void)viewDidLoad {
[super viewDidLoad];
//initData
}
Upvotes: 14