I have a TabBarController
app with a DialogViewController
that works fine except that on initial load the table is EMPTY until I touch it or navigate to another tab and back (http://cl.ly/3I0r1v2b420t0L1X1h2w).
I have confirmed the Root
is set. I've tried issuing a ReloadData()
after. I've also tried setting the TableView.Source
directly. In every case the TableView
doesn't show anything until another action occurs.
This happens in the simulator and on the iPhone.
Any idea why this might be?
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);
}
}
Curtis Bailey pointed me on the MonoTouch mailing list to look at InvokeOnMainThread. That solved this issue because the asynchronous service call is on a background thread and so too was the callback.
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);
});
}