Reputation: 1016
My application is view based in my app in one view i write view will appear but this method doesn't call. My code is
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"view will Appear");
[tableView reloadData];
}
Can anyone tell why viewWillAppear method not called.
Sorry I forgot To tell You That This method call first time but when i remove a subview from this view viewWillAppear not called. Please Suggest me how to solve this problem.
Upvotes: 1
Views: 10638
Reputation: 1016
Hi Here I did instead
[self.view addSubview:viewcontroller.view];
I Used this:
[self presentModalViewController:viewcontroller animated:YES];
and write this method now my problem is solved.
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"==========view will appear");
}
Upvotes: 0
Reputation: 2856
I think that the problem you are seeing is that viewWillAppear:
is a method on a UIViewController
, and not a method on UIView
. viewWillAppear:
is called on the view controller to indicate that the controller's view will become visible.
If you have added the code above to a class based on UIView
, that code won't get called. You need to move that code to your view controller -or- you might achieve the result that you are looking for by implementing the didMoveToSuperview
method in your UIView based class instead.
didMoveToSuperview
will be called on your view when your view is added to another view using addSubview:
.
Upvotes: 0
Reputation: 1885
The viewWillAppear and other related methods are called to the viewcontroller that are linked with the rootViewController of the mainWindow. So if you are using a view based application, the viewWillAppear method of the first view controller will work properly and others wont.
Upvotes: 0
Reputation: 13180
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"view will Appear");
[tableView reloadData];
}
if still it is not calling then try to call through code , as per example [classobj viewWillAppear:NO];
Upvotes: 3