【发布时间】:2013-03-08 12:56:23
【问题描述】:
我使用 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);
}
}
}
【问题讨论】:
-
我不确定是不是这样。但是,您自定义的根元素看起来不正确。您使用自定义根元素是否有原因?即使这是正确的,我也看不到您实际上是在哪里为
Root.add (sectionList);创建RootElement另外,如果您没有启用搜索,这是否有效? -
这是一个死问题吗?
-
没有死问题,我只是周末不工作......没有过滤器时它工作正常。获取单元格崩溃是在使用过滤器时。 RootElement 是通过LocatiesViewController 的构造函数创建的。
标签: search crash monotouch.dialog