I have a MasterDetail Application, and a NavButton to add a new item. Im am able to successfully pop the view back, however I need to reload the table nice that is done. So how exactly can my MasterViewController know when it was popped so it could reload?
Heres the Pop code:
NavigationController.PopViewController(true);
It functions as expected, I just then need MasterViewController to reload the table, which I made a method for:
public void ReloadTable()
{
TableView.ReloadData ();
}
Try this:
public partial class MasterViewController : UIViewController
{
public void ReloadTable()
{
TableView.ReloadData ();
}
}
public partial class DetailViewController : UIViewController
{
public override void ViewWillDisappear (bool animated)
{
var masterViewController = NavigationController.ViewControllers.OfType<MasterViewController> ().FirstOrDefault();
if (masterViewController != null) {
masterViewController.ReloadTable ();
}
base.ViewWillDisappear (animated);
}
}
You need to add using System.Linq;
to get the OfType method.
It can be done by checking if navigationController contains viewcontroller like this:
Note viewControllerA
pushes viewControllerB
Now in viewControllerB
use viewWillDisappear
method
- (void)viewWillDisappear:(BOOL)animated
{
if (![[self.navigationController viewControllers] containsObject: self]) //any other hierarchy compare if it contains self or not
{
// the view has been removed from the navigation stack or hierarchy, back is probably the cause
// this will be slow with a large stack however.
viewControllerA *objViewControllerA = [[self.navigationController viewControllers] lastObject];
//NSLog(@"%@",objViewControllerA);
if (objViewControllerA)
{
[objViewControllerA viewPoppedBack];
}
}
}
Now add
one method
in viewControllerA
-(void)viewPoppedBack
{
//reload tableview here
[yourTableViewHere reloadData];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.