2013-06-22 29 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

相關問題