我有一个TabBarController
应用程序,DialogViewController
工作正常,但在初始加载时,表格为EMPTY,直到我触摸它或导航到另一个标签并返回(http://cl.ly/3I0r1v2b420t0L1X1h2w)。
我已确认已设置Root
。我尝试过发布一个ReloadData()
。我也试过直接设置TableView.Source
。在每种情况下,TableView
都不会显示任何内容,直到另一个操作发生。
这发生在模拟器和iPhone上。
知道为什么会这样吗?
public partial class PapersView : DialogViewController
{
public PapersView () : base (UITableViewStyle.Plain, null, true)
{
EnableSearch = true;
AutoHideSearch = true;
SearchPlaceholder = @"Find Papers";
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;
var svc = new PaperService ();
svc.GetPapers (onPapersReceived, onErrorReceived);
}
private void onErrorReceived (string error)
{
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
}
private void onPapersReceived (List<PaperNode> papers)
{
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
Root = new RootElement ("Papers") {
from node in papers
group node by (node.paper.title [0].ToString ().ToUpper ()) into alpha
orderby alpha.Key
select new Section (alpha.Key){
from eachNode in alpha
select (Element)new WhitePaperBible.iOS.UI.CustomElements.PaperElement (eachNode)
}};
TableView.ScrollToRow (NSIndexPath.FromRowSection (0, 0), UITableViewScrollPosition.Top, false);
}
}
答案 0 :(得分:3)
Curtis Bailey指出我在MonoTouch邮件列表上查看InvokeOnMainThread。这解决了这个问题,因为异步服务调用是在后台线程上进行的,回调也是如此。
private void onPapersReceived (List<PaperNode> papers)
{
MonoTouch.UIKit.UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;
InvokeOnMainThread (delegate {
Root = new RootElement("Papers") {
from node in papers
group node by (node.paper.title [0].ToString ().ToUpper ()) into alpha
orderby alpha.Key
select new Section (alpha.Key){
from eachNode in alpha
select (Element)new WhitePaperBible.iOS.UI.CustomElements.PaperElement (eachNode)
}};
TableView.ScrollToRow (NSIndexPath.FromRowSection (0, 0), UITableViewScrollPosition.Top, false);
});
}
答案 1 :(得分:1)
尝试仅填充现有的Root,而不是创建新的Root。
如果你查看DialogViewController的MonoTouch.Dialog源代码,你应该找到PrepareRoot()方法。看看它被调用的地方,它应该开始有意义。