Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created April 10, 2012 23:33
Show Gist options
  • Save davidortinau/2355621 to your computer and use it in GitHub Desktop.
Save davidortinau/2355621 to your computer and use it in GitHub Desktop.
MonoTouch DialogViewController issue not showing data immediately
using System;
using System.Collections.Generic;
using RestSharp;
using WhitePaperBibleCore.Models;
namespace WhitePaperBibleCore.Services
{
public class PaperService
{
public PaperService()
{
}
public void GetPapers(Action<List<PaperNode>> success, Action<string> failure)
{
var client = new RestClient(Constants.BASE_URI);
var request = new RestRequest("papers.json?caller=wpb-iPhone", Method.GET) { RequestFormat = DataFormat.Json };
client.ExecuteAsync(request, (response, async) =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
failure(response.ErrorMessage);
}
else
{
success( SimpleJson.SimpleJson.DeserializeObject<List<PaperNode>>(response.Content) );
}
});
}
public void GetPaperReferences(int paperId, Action<List<ReferenceNode>> success, Action<string> failure)
{
var client = new RestClient(Constants.BASE_URI);
var request = new RestRequest("papers/" + paperId.ToString() + "/references.json?caller=wpb-iPhone", Method.GET) { RequestFormat = DataFormat.Json };
client.ExecuteAsync(request, (response, async) =>
{
if (response.ResponseStatus == ResponseStatus.Error)
{
failure(response.ErrorMessage);
}
else
{
success( SimpleJson.SimpleJson.DeserializeObject<List<ReferenceNode>>(response.Content) );
}
});
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
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;
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