gpt4 book ai didi

c# - MonoTouch.Dialog 搜索栏在返回 View 时丢失搜索查询

转载 作者:行者123 更新时间:2023-12-02 05:45:40 26 4
gpt4 key购买 nike

我正在使用 MT.D 列出 DialogViewController 中的员工。 EnableSearch 已打开,您可以过滤列表中的项目。然而,如果你推到另一个 View ,然后返回,搜索栏是空的。我能够通过覆盖 OnSearchTextChanged (string text) 并将字符串存储到本地字段来恢复使用的搜索查询,当 View 重新获得焦点时,我使用以下代码:

public override ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
if (EnableSearch && !string.IsNullOrWhiteSpace (lastSearchQuery))
{
this.SearchButtonClicked (lastSearchQuery); // this inserts text
this.StartSearch (); // no clue what this is doing
this.ReloadData (); // does nothing but was worth a try
}
}

该代码将文本插入搜索栏并显示它,但除非您键入内容,否则我无法对其进行过滤。键盘出现在视野中,并且有一个搜索按钮,但它什么也没做。有什么建议么?

最佳答案

我认为您所缺少的只是对 DialogViewController 上的 PerformFilter 的调用。

我键入了一个快速示例来展示行为。我从来没有看到你观察到的确切行为。我不必重新填充搜索字段。作为引用,我使用的是 Monotouch 5.2.11。

using System;
using System.Linq;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
using MonoTouch.Foundation;

namespace delete201204242A
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow _window;
UINavigationController _nav;
MyDialogViewController _rootVC;

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
_window = new UIWindow (UIScreen.MainScreen.Bounds);

RootElement _rootElement = new RootElement ("LINQ root element") {
new Section ("List") {
from x in new Expense [] { new Expense () {Name="one"}, new Expense () {Name="two"}, new Expense () {Name="three"} }
select (Element)new BindingContext (null, x, x.Name).Root
}
};

_rootVC = new MyDialogViewController (_rootElement);
_rootVC.EnableSearch = true;
_nav = new UINavigationController (_rootVC);

_window.RootViewController = _nav;

_window.MakeKeyAndVisible ();

return true;
}

public class MyDialogViewController : DialogViewController
{
public MyDialogViewController (RootElement root) : base (root) {}

public string SearchString { get; set; }
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
if (!string.IsNullOrEmpty (SearchString))
this.PerformFilter (SearchString);
}
public override void OnSearchTextChanged (string text)
{
base.OnSearchTextChanged (text);
SearchString = text;
}
}

public class Expense
{
[Section("Expense Entry")]

[Entry("Enter expense name")]
public string Name;
[Section("Expense Details")]

[Caption("Description")]
[Entry]
public string Details;
}

}
}

关于c# - MonoTouch.Dialog 搜索栏在返回 View 时丢失搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10306064/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com