gpt4 book ai didi

search - Monotouch.Dialog:EnableSearch和自定义RootElement崩溃

转载 作者:行者123 更新时间:2023-12-03 17:39:20 26 4
gpt4 key购买 nike

我使用Monotouch.Dialog(Xamarin.iOS版本:6.2.0.65)创建带有RadioElements的RadioGroup。我只想要第二个屏幕(用户从长列表中选择)的“搜索”功能,所以我创建了一个单独的DialogViewController,在其中启用了搜索过滤器(enableSearch = true)。

在搜索框中键入内容时,应用程序会在RadioElement的GetCell方法中崩溃。

Element.cs的第1064行上的“对象引用未设置为对象的实例”。我有GC问题吗?我设法在一个小型应用程序中对其进行了仿真。。。不要关注一些奇怪的领域成员,那就是我测试是否要开始使用GC ...

using MonoTouch.Dialog;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace SearchCrash
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
public UINavigationController NavigationController { get; set; }

//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
this.NavigationController = new UINavigationController();
this.NavigationController.PushViewController(new FirstViewController(this.NavigationController), true);
window.RootViewController = this.NavigationController;
window.MakeKeyAndVisible();

return true;
}
}

public class FirstViewController : DialogViewController
{
private UINavigationController controller;
private LocatiesRootElement locRootElement;
private RadioGroup radioGroup;

public FirstViewController(UINavigationController c) : base(new RootElement("Test"), true)
{
this.controller = c;
}

public override void ViewDidLoad()
{
Section section = new Section();
radioGroup = new RadioGroup(0);
locRootElement = new LocatiesRootElement("test", radioGroup, this.controller);
section.Add(locRootElement);
Root.Add(section);
}
}

public class LocatiesRootElement : RootElement
{
private UINavigationController navigationController;
private LocatiesViewController locatiesViewController;

public LocatiesRootElement(string selectedLocatie, RadioGroup group, UINavigationController controller) : base("Locatie", group)
{
this.navigationController = controller;
this.locatiesViewController = new LocatiesViewController(this);
}

public override void Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
this.navigationController.PushViewController(this.locatiesViewController, true);
}
}

public class LocatiesViewController : DialogViewController
{
public LocatiesViewController(LocatiesRootElement root) : base(root, true)
{
this.EnableSearch = true;
}

public override void ViewDidLoad()
{
base.ViewDidLoad();

Section sectionList = new Section();

RadioElement radioElement1 = new RadioElement("item 1");
RadioElement radioElement2 = new RadioElement("item 2");
sectionList.Add(radioElement1);
sectionList.Add(radioElement2);

Root.Add(sectionList);
}
}
}

最佳答案

实例化DialogViewController后,尝试启用搜索。

像这样 :

public LocatiesRootElement(string selectedLocatie, RadioGroup group, UINavigationController controller) : base("Locatie", group)
{
this.navigationController = controller;
this.locatiesViewController = new LocatiesViewController(this);
this.locatiesViewController.EnableSearch = true;
}

希望这对您有用。

关于search - Monotouch.Dialog:EnableSearch和自定义RootElement崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15294509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com