中断搜索的原因是 DialogViewController 在 UISearchBar 上分配了一个自定义 UISearchBarDelegate。
当您连接到一个事件时,它会破坏委托并将其替换为一个特殊的 UISearchBarDelegate,它将所有委托方法转发给事件。
换句话说,您不能将委托与同一控件上的事件混合和匹配。
一种可能的解决方案(如果您不想修补 MonoTouch.Dialog 本身)是用您自己的自定义 UISearchBarDelegate 替换现有的 sb.Delegate,它可以实现 SearchScope 方法并将其他所有内容转发到之前已经设置的 UISearchBarDelegate。
例如:
public class MySearchBarDelegate : UISearchBarDelegate
{
UISearchBarDelegate original;
MyDialogViewController dvc;
public MySearchBarDelegate (MyDialogViewController dvc, UISearchBarDelegate original)
{
this.original = original;
}
public override void SelectedScopeButtonIndexChanged (UISearchBar searchBar, int selectedScope)
{
dvc.Update ();
}
public override void OnEditingStarted (UISearchBar searchBar)
{
original.OnEditingStarted (searchBar);
}
public override void OnEditingStopped (UISearchBar searchBar)
{
original.OnEditingStopped (searchBar);
}
public override void TextChanged (UISearchBar searchBar, string searchText)
{
original.TextChanged (searchBar, searchText);
}
public override void CancelButtonClicked (UISearchBar searchBar)
{
original.CancelButtonClicked (searchBar);
}
public override void SearchButtonClicked (UISearchBar searchBar)
{
original.SearchButtonClicked (searchBar);
}
}