Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created April 10, 2012 23:39
Show Gist options
  • Save davidortinau/2355654 to your computer and use it in GitHub Desktop.
Save davidortinau/2355654 to your computer and use it in GitHub Desktop.
Invoking Callback on Main Thread fixes DialogViewController issue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using WhitePaperBibleCore.Models;
using WhitePaperBibleCore.Services;
using WhitePaperBible.iOS.TableSource;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
namespace WhitePaperBible.iOS
{
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;
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);
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment