显示后将元素添加到 MonoTouch 对话框 RootElement 时出现奇怪的块 [英] Weird blocks when adding Elements to MonoTouch Dialog RootElement after it is shown
问题描述
在我正在构建的应用程序中,我使用以下模式:如果用户单击分层导航元素,我会立即打开下一个 UIViewController
,它会自行加载数据并显示一个如果通过网络加载微调器.
In an app I am building I use the following pattern: If the user clicks on a hierarchical navigation element I open the next UIViewController
immediately, and it takes care about loading its data itself and shows a loading spinner if it is going over the network.
现在大多数列表视图都是使用 MonoTouch
创建的.在一个 DialogViewController
上,我在屏幕已经显示后向视图 RootElement 添加许多元素时遇到问题.
Now most list views are created using MonoTouch
. On one DialogViewController
I have an issue with adding many element to the views RootElement after the screen has already been show.
起初 StringElements
在屏幕上看起来不错,但是如果你快速上下滚动,每行上的文本就会变成一个块:
At first the StringElements
appear fine on screen, but if you scroll quickly up and down the text on each line becomes a 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);
});
});
有趣的是,只有左边的字符串看起来像一个块,而右边的则很好.附带说明一下,在他们的 MWC(演示)应用程序中,Xamarin 创建了一个新的 RootElement 来重新填充 Twitter 列表.
Interestingly only the string on the left looks like a block, while the one on the right is fine. On a side note, in their MWC (demo) app, Xamarin created a new RootElement to repopulate the twitter list as well.
推荐答案
似乎没有重新加载在主线程上调用的数据源以正确呈现新值:
There does not seem to be a reload of the data source called on the main thread to correctly render the new values:
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();
});
});
这篇关于显示后将元素添加到 MonoTouch 对话框 RootElement 时出现奇怪的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!