objective c - reloadData Crashing iOS App -
i'm doing twitter request api data with:
twrequest *postrequest = [[twrequest alloc] initwithurl:[nsurl urlwithstring:@"http://search.twitter.com/search.json?q=a2zwedding&include_entities=true"] parameters:nil requestmethod:twrequestmethodget];
then i'm getting processing request with:
[postrequest performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) { // nsstring *output; nsarray *results; if ([urlresponse statuscode] == 200) { nserror *jsonparsingerror = nil; nsdictionary *publictimeline = [nsjsonserialization jsonobjectwithdata:responsedata options:0 error:&jsonparsingerror]; results = [publictimeline objectforkey:@"results"]; } [self performselectoronmainthread:@selector(populatetable:) withobject:results waituntildone:yes]; }];
i'm trying display "results" in uitableview. delegate , datasource same view controller processing json data. datasource method of:
- (nsinteger)tableview:(uitableview*)tableview numberofrowsinsection:(nsinteger)section
is returning 0 if try count of array because json parsing isn't finished when gets called. if "return 1" method, displays 1 of results twitter request. however, if use reloaddata app crashes. cannot delay count. ideas?
in .h
//use datasource @property(nonatomic, strong)nsarray *myresultdata;
.m
@synthesize myresultdata; [postrequest performrequestwithhandler:^(nsdata *responsedata, nshttpurlresponse *urlresponse, nserror *error) { // nsstring *output; nsarray *results; if ([urlresponse statuscode] == 200) { nserror *jsonparsingerror = nil; nsdictionary *publictimeline = [nsjsonserialization jsonobjectwithdata:responsedata options:0 error:&jsonparsingerror]; results = [publictimeline objectforkey:@"results"]; if(![results iskindofclass:[nsnull class]]) { myresultdata = [nsarray alloc]initwitharray:results]; } [self.tableview reloaddata]; } }];
Comments
Post a Comment