ios - Table view populated from NSMutableArray not showing anything -


i trying populate tableview objects received json request.

this viewdidload method:

- (void)viewdidload {     [super viewdidload];      nslog (@"he entrado en historial vc");     myobject = [[nsmutablearray alloc] init];     nsurl *apiurl = [nsurl urlwithstring:                      [nsstring stringwithformat:@"http://.. hidden here.. /?client=%@&date=%@", @"1",@"2015-3-16"]];     nsurlrequest *request = [nsurlrequest requestwithurl:apiurl];      nslog (@"he mandado la request del historial");     [nsurlconnection sendasynchronousrequest:request                                        queue:[nsoperationqueue mainqueue]                            completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) {                                if(data.length) {                                    nsstring *responsestring = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];                                    if(responsestring && responsestring.length) {                                        nslog(@"datos recibidos en historial=%@", responsestring);                                         nslog (@"he recibido la request del historial");                                        nserror *jsonerror;                                        nsdata *objectdata = [responsestring datausingencoding:nsutf8stringencoding];                                        nsdictionary *json = [nsjsonserialization jsonobjectwithdata:objectdata                                                                                             options:nsjsonreadingmutablecontainers                                                                                               error:&jsonerror];                                        nsarray *messagearray = [json objectforkey:@"objects"];                                         historialservicios = [[nsmutablearray alloc]init];                                         // parse , loop through json                                        (dictionary in messagearray) {                                            //datos de nivel objects                                            nsstring * code = [dictionary objectforkey:@"code"];                                            nsstring * date = [dictionary objectforkey:@"date"];                                              //datos de nivel client                                            nsdictionary *level2dict = [dictionary objectforkey:@"client"];                                            id someobject = [level2dict objectforkey:@"email"];                                            nslog(@"antes de anadir objetos");                                             [historialservicios addobject:@{@"code": code, @"date": date, @"email":someobject}];                                            nslog(@"despues de anadir objetos");                                             nslog(@"nombre===%@",someobject);                                             nsstring * email = someobject;                                            nslog(@"email=%@",email);                                            nslog(@"code=%@",code);                                            nslog(@"date=%@",date);                                             //insertamos objetos en diccionario historialservicios                                        }                                          nslog(@"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++servicios recibidos=%@", historialservicios);                                    }                                 }                            }];      nslog(@"numero de items=%lu", (unsigned long)[historialservicios count]);     [self.tableview reloaddata]; } 

the last nslog doesn't appear in log console. content of nsmutablearray shown in console:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++servicios recibidos=(         {         code = sv1000000103;         date = "2015-03-18";         email = "jose@gmail.com";     },         {         code = sv1000000113;         date = "2015-03-18";         email = "jose@gmail.com";     },         {         code = sv1000000104;         date = "2015-03-16";         email = "jose@gmail.com";     }, ... 

but nothing shown on table.

here tableview methods:

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section{     return historialservicios.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{         uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath];       nsstring *email = [[historialservicios objectatindex:indexpath.row] valueforkey:@"email"];     nslog(@"valor del email=%@", email);     cell.detailtextlabel.text = email;     return cell; } 

what doing wrong?

you should call [self.tableview reloaddata] inside completion block after "servicios recibidos=%@" line.

calling outside block did, make table reloads contents before receive server.

hope helps you, amigo.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -