ios - Loading JSON on UITableView w/ Monotouch -


i using xamarin.ios return json , attempt place on uitableview, overriding tostring() in datum class in instagram client class, want able fix can load more names...

here instagram client turns json class objects:

public class rootobject {     public pagination pagination { get; set; }     public meta meta { get; set; }     public list<datum> data { get; set; } }  public class datum {     public object attribution { get; set; }     public list<string> tags { get; set; }     public string type { get; set; }     public object location { get; set; }     public comments comments { get; set; }     public string filter { get; set; }     public string created_time { get; set; }     public string link { get; set; }     public likes likes { get; set; }     public images images { get; set; }     public list<object> users_in_photo { get; set; }     public caption caption { get; set; }     public bool user_has_liked { get; set; }     public string id { get; set; }     public user user { get; set; }     public videos videos { get; set; }                // overridden method want rid of      public override string tostring()     {         if (user == null)         {             return "user null";         }         return user.full_name;     } }  public class videos {     public lowresolution2 low_resolution { get; set; }     public standardresolution2 standard_resolution { get; set; } }  public class standardresolution2 {     public string url { get; set; }     public int width { get; set; }     public int height { get; set; } }  public class lowresolution2 {     public string url { get; set; }     public int width { get; set; }     public int height { get; set; } }  public class user {     public string username { get; set; }     public string website { get; set; }     public string profile_picture { get; set; }     public string full_name { get; set; }     public string bio { get; set; }     public string id { get; set; } }  public class caption {     public string created_time { get; set; }     public string text { get; set; }     public from { get; set; }     public string id { get; set; } }  public class {     public string username { get; set; }     public string profile_picture { get; set; }     public string id { get; set; }     public string full_name { get; set; } }  public class images {     public lowresolution low_resolution { get; set; }     public thumbnail thumbnail { get; set; }     public standardresolution standard_resolution { get; set; } }  public class standardresolution {     public string url { get; set; }     public int width { get; set; }     public int height { get; set; } }  public class thumbnail {     public string url { get; set; }     public int width { get; set; }     public int height { get; set; } }  public class lowresolution {     public string url { get; set; }     public int width { get; set; }     public int height { get; set; } }  public class likes {     public int count { get; set; }     public list<datum2> data { get; set; } }  public class datum2 {     public string username { get; set; }     public string profile_picture { get; set; }     public string id { get; set; }     public string full_name { get; set; } }  public class comments {     public int count { get; set; }     public list<object> data { get; set; } }  public class meta {     public int code { get; set; } }  public class pagination {     public string next_url { get; set; }     public string next_max_id { get; set; } } 

main view controller

this how returning json

var request = new restrequest { rootelement = "data", resource = "/users/self/feed" };             request.addparameter ("access_token", instagramaccesstoken);              var client = new restclient ("https://api.instagram.com/v1");             client.executeasync (request, response => {                 var rootobject = jsonconvert.deserializeobject<rootobject> (response.content);                 table.invokeonmainthread (() => {                     table.source = new tablesource<datum>(rootobject.data);                     table.reloaddata ();                 });             }         ); 

tablesource class

            public list<t> data { get; set; }     protected string cellidentifier = "tablecell";      public tablesource ()     {         data = new list<t> ();     }      public tablesource(list<t> data)     {         data = data;     }      public override int rowsinsection (uitableview tableview, int section)     {         return data.count;     }      public override void rowselected (uitableview tableview, nsindexpath indexpath)     {         if (onrowselected != null) {             onrowselected (this, new rowselectedeventargs (tableview, indexpath));         }     }      public class rowselectedeventargs : eventargs     {         public uitableview tableview { get; set; }         public nsindexpath indexpath { get; set; }          public rowselectedeventargs(uitableview tableview, nsindexpath indexpath) : base()         {              this.tableview = tableview;             this.indexpath = indexpath;         }     }      public event eventhandler<rowselectedeventargs> onrowselected;      public override uitableviewcell getcell (uitableview tableview, monotouch.foundation.nsindexpath indexpath)     {          if (tableview.contentsize.height - uiscreen.mainscreen.bounds.height <= tableview.contentoffset.y) {             // last row in last section             console.writeline ("~~~bottom~~~");         }          uitableviewcell cell = tableview.dequeuereusablecell (cellidentifier);         // if there no cells reuse, create new 1         if (cell == null)             cell = new uitableviewcell (uitableviewcellstyle.default, cellidentifier);          // edited text          cell.textlabel.text = data[indexpath.row].tostring ();          return cell;     } 

i didn't have concrete method of displaying json on table, pretty open radical change.

in getcell method can access property of data. want create custom uitableviewcell if want display more 2 lines of data.

var item = data[indexpath.row]; cell.textlabel.text = item.user.username + " (" + item.user.full_name + ")"; cell.detailtextlabel.text = "created at: " + item.created_time; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -