Ho una situazione in cui la mia tabella si sta caricando prima di ottenere i dati dal mio webservice.UITableView visualizzato prima di ricevere dati da connectionDidFinishLoading
Quando eseguo il debug, posso vedere che il mio NSMutableArray
ha 123 oggetti, ma non viene riflesso nella tabella.
Questo è il mio metodo connectionDidFinishLoading
:
-(void)connectionDidFinishLoading:(NSURLConnection *)conn{
myData = [[NSString alloc] initWithData:xData encoding:NSUTF8StringEncoding];
SBJsonParser *jParser = [SBJsonParser new];
NSError *error = nil;
NSArray *jsonObjects = [jParser objectWithString:myData error:&error];
NSMutableArray *books = [[NSMutableArray alloc] init];
for(NSDictionary *dict in jsonObjects)
{
Book *b = [Book new];
b.bookName =[dict objectForKey:@"name"];
b.published = [dict objectForKey:@"published"];
[books addObject:b];
}
self.bookArray = books;
[self.tableView reloadData];
NSLog(@"myData = %@",myData);
}
Se metto a punto questo che ricevo la mia jsonObjects
e lo ha popolato la mia collezione. Ma noto che il mio tavolo è ancora vuoto.
Giusto per chiarire questo è il mio metodo tableView
:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
...
Book *b = (Book *)[self.bookArray objectAtIndex:[indexPath row]];
cell.textLabel.text = b.bookName;
....
qualcuno mi può aiutare con quello che mi manca?
Vediamo l'intero metodo cellForRow. Hai implementato rowsForSection? – Dancreek
@Dancreek Immagino tu intenda numberOfRowsForSection? Comunque, quello e [tableview reloadData] è stato il mio sospetto quando ho letto l'argomento. Sta chiamando però reloadData, il che elimina quest'ultimo. – barley
- TableView (NSInteger): (UITableView *) tableView numberOfRowsInSection: sezione (NSInteger) { return bookArray.count; } – Matt