ios - 显示后将元素添加到 MonoTouch 对话框 RootElement 时出现奇怪的 block

标签 ios xamarin.ios monotouch.dialog

在我正在构建的应用程序中,我使用以下模式:如果用户单击分层导航元素,我会立即打开下一个 UIViewController,它会自行加载数据并显示如果通过网络加载微调器。

现在大多数 ListView 都是使用 MonoTouch 创建的。在一个 DialogViewController 上,我在屏幕已经显示后向 View RootElement 添加许多元素时遇到问题。

一开始 StringElements 在屏幕上看起来很好,但是如果您快速上下滚动,每行上的文本就会变成一个 block :

screenshot of the issue at hand

重现问题的代码:

        var root = new RootElement("Root");
        var dvc = new DialogViewController(root) { AutoHideSearch = true, EnableSearch = true };

        nav.PushViewController(dvc, true);

        Task.Factory.StartNew(() => {
                Thread.Sleep(TimeSpan.FromSeconds(1));
            UIApplication.SharedApplication.InvokeOnMainThread(() => {
                var sec = new Section();

                for (int i = 0; i < 100; i++)
                {
                    var el = new StyledStringElement("Test", "Test", UITableViewCellStyle.Value1);
                    sec.Add(el);
                }

                root.Add(sec);
            });
        });

有趣的是只有左边的字符串看起来像 block ,而右边的没问题。附带说明,在他们的 MWC(演示)应用程序中,Xamarin created a new RootElement to repopulate the twitter list as well .

最佳答案

似乎没有在主线程上重新加载数据源以正确呈现新值:

var dvc = new DialogViewController(new RootElement(""));
_root = new UINavigationController();
_root.PushViewController(dvc, true);
_window.RootViewController = _root;

Task.Factory.StartNew(() => {
    Thread.Sleep(TimeSpan.FromSeconds(1));
    var section = new Section("");
        foreach (var i in Enumerable.Range(1, 100)) {
            section.Add(new StyledStringElement(i.ToString(), "cell", UITableViewCellStyle.Value1));
        }

    dvc.Root.Add(section);
    BeginInvokeOnMainThread(() => {
        dvc.ReloadData();
    });
});

关于ios - 显示后将元素添加到 MonoTouch 对话框 RootElement 时出现奇怪的 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9456650/

相关文章:

ios - 当前索引与错误数据关联

ios - swift : Cannot convert value of type '()' to expected argument type '[Double]'

encryption - 使用 Xamarin 保护跨平台存储选项

Xamarin 中缺少 Azure 移动服务 InvokeApi

c# - 使用带有 monotouch.dialog 的标签栏 Controller

ios - MonoTouch.Dialog 与 UISplitViewController

android - 是否可以在 Flutter 中完全处理音量增大/减小产生的事件?

ios - iOS 应用程序中的文档目录是否会自动删除?

c# - Monotouch Crashdump 缺少对我的代码的任何引用

c# - 使用 MonoTouch.Dialog 设置 View 背景颜色