2013-03-08 18 views
0

我使用Monotouch.Dialog(Xamarin.iOS版本:6.2.0.65)来创建一个放射性元素RadioGroup中。我只想在第二个屏幕(用户从长列表中选择)中搜索功能,所以我创建了一个单独的DialogViewController,其中我启用了搜索过滤器(enableSearch = true)。Monotouch.Dialog:碰撞与EnableSearch和定制rootElement的

当在搜索框中输入,在放射性元素的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); 
    }   
} 
} 
+0

我不知道这是它。但是,你是自定义的根元素看起来不正确。您是否有使用自定义根元素的原因?即使这是正确的,我也没有看到为Root.add(sectionList)实际创建'RootElement'的位置;'另外,如果您没有启用搜索,这是否工作? – BRogers 2013-03-08 17:52:45

+0

这是一个死的问题吗? – BRogers 2013-03-11 01:13:03

+0

没有死的问题,我只是没有在周末工作......它没有过滤器时工作正常。获取单元崩溃时使用过滤器。 RootElement是通过LocatiesViewController的构造函数创建的。 – Peesjee 2013-03-11 07:35:12

回答

0

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

像这样:

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

希望这会为你工作。

+0

不,同样的问题。 – Peesjee 2013-03-12 07:40:01

0

bug报告这里包括对问题的根源您遇到一个解决办法,但也是关于过滤怎么会进而导致所选择的过滤器已应用于即使标志着第n个元素的可用性问题举行了会谈。

https://github.com/migueldeicaza/MonoTouch.Dialog/issues/203

如果你不想更新核心MTD的代码,你可以通过将其放在自己的UIBarSearchDelegate使用同样的技术。不幸的是,默认的SearchDelegate类是内部的,所以你需要在代理中添加所有的代码。我能做到这一点,得到它的工作,而不改变MTD来源:

public override void LoadView() 
    { 
     base.LoadView(); 
     ((UISearchBar)TableView.TableHeaderView).Delegate = new MySearchBarDelegate(this); 
    } 

然后你使用它来代替基本方法:

public override void TextChanged (UISearchBar searchBar, string searchText) 
{ 
    container.PerformFilter (searchText ?? ""); 
    foreach (var s in container.Root) 
     s.Parent = container.Root; 
}