Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UISearchController限制搜索_Ios_Xamarin_Xamarin.ios - Fatal编程技术网

Ios 使用UISearchController限制搜索

Ios 使用UISearchController限制搜索,ios,xamarin,xamarin.ios,Ios,Xamarin,Xamarin.ios,我有一个Xamarin.iOS应用程序,它可以在一个长列表上进行一些搜索,这需要一些时间。我想引入一些限制,而不是搜索每个按键。有什么想法吗?您可以使用反应式扩展,即使用C风格的事件而不是iOS委托 以下是UITextView的基本示例代码: var observable = Observable.FromEventPattern<EventArgs> ( //Those are actions used to subscribe and unsubscribe for the

我有一个Xamarin.iOS应用程序,它可以在一个长列表上进行一些搜索,这需要一些时间。我想引入一些限制,而不是搜索每个按键。有什么想法吗?

您可以使用反应式扩展,即使用C风格的事件而不是iOS委托

以下是UITextView的基本示例代码:

var observable = Observable.FromEventPattern<EventArgs>
(
   //Those are actions used to subscribe and unsubscribe for the event
   eventHandler => TextView.Changed += eventHandler,
   eventHandler => TextView.Changed -= eventHandler
) 
.Sample(TimeSpan.FromMilliseconds(500))  //This will sample every 500 to check if the event has been raised
.Select(e => e.Sender as UITextView) //This is used so we can directly use  the TextView in the subscribe method


observable.Subscribe(textView =>
{
    //This will be executed if the event was raised the last 500 miliseconds
    //This may not run on the UI thread
    InvokeOnMainThread(() => Label.Text = textView.Text);
});
在Select方法之后,如果文本为空或要进行一些其他检查,则它不会引发事件

我在观看Xamarin Evolve 2016的演示时发现了这一点,该演示是视频的链接。并且是到源代码的链接


样本在Xamarin.Forms上,但它们将为您提供一个良好的起点。

通常的方法是等待最少的按键次数。这在您即将推出API服务时非常有用!您还可以引入一些缓存,以防它们按delete键或重新输入相同的键。键入键时启动计时器。如果键入了另一个键,请重新启动计时器。当计时器启动时,执行搜索我确实非常喜欢这一个,但我没有使用Rx(我现在更关注基本)。在这种情况下,我将使用NSTmer定期对文本进行采样,如果需要搜索,则执行一些检查,然后再搜索。感谢您的回答,它们都是有价值的回答。现在将购买NSTimer,但毫无疑问,投资Rx是值得的。
  .Where(textView => !String.IsNullOrWhiteSpace(textView.Text) || !IsCompleteNonSense(textView.Text));