在我正在构建的应用程序中,我使用以下模式:如果用户单击分层导航元素,我会立即打开下一个 UIViewController
,它会自行加载数据并显示如果通过网络加载微调器。
现在大多数 ListView 都是使用 MonoTouch
创建的。在一个 DialogViewController
上,我在屏幕已经显示后向 View RootElement 添加许多元素时遇到问题。
一开始 StringElements
在屏幕上看起来很好,但是如果您快速上下滚动,每行上的文本就会变成一个 block :
重现问题的代码:
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/