ios - Monotouch - 无法在单击按钮时关闭当前 View

标签 ios uinavigationcontroller xamarin.ios

我有一个让用户编辑 EntryElement 的 View 。我通过“完成”按钮的委托(delegate)很好地注册了点击事件,但是我无法让它关闭当前 View 以转到上一个 View 。这是我现在正在尝试的:

AppDelegate.navigation.PresentedViewController.DismissViewController(true, null);

我也试过:

AppDelegate.navigation.PresentedViewController.RemoveFromParentViewController();

navigation 只是一个 UINavigationController

编辑:

我正在使用 Monotouch.Dialog 构建所有 View 。这个 View 是通过一个方法创建的。一旦他们单击完成按钮,我希望它返回到以前的 View 。以下是方法的内容:

public static void EditClientTypeView (string typeName, string typeId)
        {
            DialogViewController editClientTypeVC;
            UIBarButtonItem doneButton = new UIBarButtonItem (UIBarButtonSystemItem.Done);

            EntryElement element = new EntryElement("Type Name", "Name of client type", typeName, false);

            var root = new RootElement ("Edit Type") {
                new Section () {
                    element
                }
            };

            editClientTypeVC = new DialogViewController (root, true);
            editClientTypeVC.NavigationItem.RightBarButtonItem = doneButton;

            doneButton.Clicked += (sender, e) => {
                // Need to save the edited client type to the database
                Console.WriteLine("Done button clicked signifying the user is finished editing");
                AppDelegate.navigation.PresentedViewController.RemoveFromParentViewController();
                //AppDelegate.navigation.DismissViewController(true, null);
            };

            AppDelegate.navigation.PushViewController(editClientTypeVC, true);
        }

感谢任何帮助!

最佳答案

由于您将 View Controller 推送到导航堆栈,因此您可以通过将其弹出堆栈来关闭它。 UINavigationController具有三种POP方法

  • PopToRootViewController - 一直返回到导航 Controller 的 Root View
  • PopToViewController - 弹回到特定的 View Controller
  • PopViewController - 弹回“上一个” View Controller

关于ios - Monotouch - 无法在单击按钮时关闭当前 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14886209/

相关文章:

iOS Xcode 4 UINavigationController

iphone - 如何隐藏 UINavigationController 的后退按钮?

ios - FFmpeg iOS 从 AVFrame 获取 UIImage

ios - 快速从 iOS 应用导出文件

ios - 当用户单击 xcode 7 中的按钮时无法打开拨号程序

ios - 是否可以弹出 UINavigationController 两次?

ios - Firebase 可以离线使用 React Native 吗?

iphone - 子类化 UINavigationController 的步骤

c# - 如何在没有 System.UnauthorizedAccessException 的情况下将文件从应用程序包复制到另一个目录?

xamarin - 设置 View 的背景图像,并进行拉伸(stretch)以适应 Xamarin