弹出视图时是否有iOS覆盖?

时间:2015-06-25 15:26:43

标签: c# ios xamarin xamarin.ios

我有一个MasterDetail应用程序和一个NavButton来添加一个新项目。我能够成功地弹回视图,但是我需要重新加载完成的表。那么我的MasterViewController究竟能够知道它何时被弹出以便重新加载?

继承Pop代码:

NavigationController.PopViewController(true);

它按预期运行,然后我需要MasterViewController重新加载表,我为它做了一个方法:

public void ReloadTable()
{
    TableView.ReloadData ();
}

2 个答案:

答案 0 :(得分:2)

试试这个:

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);
    }
}

您需要添加using System.Linq;才能获取OfType方法。

答案 1 :(得分:1)

的Objective-C

可以通过检查navigationController是否包含这样的viewcontroller来完成:

注意 viewControllerA推送viewControllerB

现在使用viewControllerB使用viewWillDisappear方法

- (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];
    }
  }
}

add

中的methodviewControllerA
 -(void)viewPoppedBack
 {
    //reload tableview here
    [yourTableViewHere reloadData];
 }