NSDictionary *json = [responseString JSONValue];
Status *statut = [[Status alloc] init];
statut.flyNumber = [json objectForKey:@"flynumber"];
statut.ftatuts = [json objectForKey:@"fstatuts"];
statut.escDepart = [json objectForKey:@"escdepart"];
statut.escArrival = [json objectForKey:@"escarrival"];
statut.proArrival = [json objectForKey:@"proarrival"];
statut.proDepart = [json objectForKey:@"prodepart"];
statut.estDepart = [json objectForKey:@"estdepart"];
statut.estArrival = [json objectForKey:@"estarrival"];
statut.realDepart = [json objectForKey:@"realdepart"];
statut.realArrival = [json objectForKey:@"realarrived"];
[dataToDisplay addObject:statut];
但如果我愿意这样做:
Status *statut2 = [dataToDisplay objectAtIndex:indexPath.row];
NSLog(@"2 ok");
cell.textLabel.text = [NSString stringWithFormat:@" %@ %@",statut2.escDepart,statut2.escArrival];
NSLog(@"3 ok");
return cell;
所有信息都在一行中。但我想在不同的行中构建我的信息。例如,在第一个例子中,我想把statut.escDepart和escArrival放在第二个statut.proDepart和statut.proArrival中。 ... 我试着遵循这个例子,
// declare this enum in your .h file
enum {
flyNumberRow = 0, // first row in tableView
ftatutsRow = 1, // second row
escDepartRow = 2, // etc.
escArrivalRow = 3,
proArrivalRow = 4,
proDepartRow = 5,
estDepartRow = 6,
estArrivalRow = 7,
realDepartRow = 8,
realArrivalRow = 9
}
Status *statut2 = [dataToDisplay objectAtIndex:indexPath.row];
switch(indexPath.row) {
case flyNumberRow:
cell.textLabel.text = [NSString stringWithFormat:@"%@",statut2.flyNumber];
break;
case ftatutsRow:
cell.textLabel.text = [NSString stringWithFormat:@"%@",statut2.ftatuts];
break;
// ... and so on for each case
}
return cell;
Evidently, tableView:numberOfRowsInSection: must return 10
但是它不起作用。我有错误。帮助我请求 这是错误。 http://hpics.li/b5653ce
答案 0 :(得分:0)
您要在Status
中添加dataToDisplay
的单个实例。因此,当请求第二行时,dataToDisplay
没有第二个对象,并且您的应用程序正在崩溃。我不认为你应该在这里使用数组。由于您已知道单元格的数量,因此请手动将numberOfRowsInSection:
作为10.而不是数组对象,请保留Status
对象。然后在tableView:cellForRowAtIndexPath:
中,使用switch语句为单元格赋值。从我看到的,你可以摆脱dataToDisplay
。