2013-06-22 24 views
0

我有一个RadioGroup有非常多RadioElements为一分DialogViewController如何在MonoTouch.Dialog中启用搜索RadioGroup DVC?

Root.Add(
    new Section() { 
     new RootElement ("Demo", new RadioGroup ("demogroup", 0)) { 
      new Section() { 
       from demoItem in bigItemList 
        select (Element) new RadioElement (demoItem) 
      } 
     } 
    } 
); 

我想启用此嵌套DVC搜索做出选择合适的RadioElement简单。为此我实现了自定义RootElement它结合了经过一个组,创建具有EnableSearch一个DVC,并用它来代替上述的一个:

using System.Collections.Generic; 

namespace MonoTouch.Dialog 
{ 
    public class SearchableRootElement : RootElement 
    { 
     public SearchableRootElement(string caption, Group group) : base(caption, group) 
     { 
      this.createOnSelected = x => { 
       return new DialogViewController(x) { EnableSearch = true }; 
      }; 
     } 
    } 
} 

不幸的是输入到子DVC我得到以下崩溃的搜索栏时:

Unhandled Exception: 
System.NullReferenceException: Object reference not set to an instance of an object 
    at MonoTouch.Dialog.RadioElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1066 
    at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:341 
    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) 
    at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
    at Demo.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rodjatrappe/Projects/Claas/Dev/Apps/Demo.iOS/Main.cs:16 
2013-06-22 14:15:02.296 DemoiOS[547:21b03] Unhandled managed exception: Object reference not set to an instance of an object (System.NullReferenceException) 
    at MonoTouch.Dialog.RadioElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x00019] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/Elements.cs:1066 
    at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:341 
    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) 
    at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
    at Demo.iOS.Application.Main (System.String[] args) [0x00001] in /Users/rodjatrappe/Projects/Claas/Dev/Apps/Demo.iOS/Main.cs:16 

为什么它崩溃以及如何归档上述功能?

回答

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; 
} 
+0

感谢。进入相同的问题,党用你的建议解决它。但是,这是如何解决即使在应用了过滤器之后也将第n个元素标记为选中状态的可用性问题?此问题是否仍然存在于您建议的解决方案中,还是我缺少部分观点?谢谢! – Corstiaan

相关问题