但如果我这样做:
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 .... 我试着遵循这个例子,
All information will be in one row .But i want to structured my informations in differents rows .For exemple in the first exemple , i want to put statut.escDepart and escArrival , in the second statut.proDepart and statut.proArrival .... I tried to follow this exemple ,
// 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但它不是'工作。我有错误。帮助我pleaaaase 这是错误。 hpics.li/b5653ce
But it don't work .I have errors.Help me pleaaaase this is the error . hpics.li/b5653ce
推荐答案您在 dataToDisplay 中添加了 Status 的单个实例。因此,当请求第二行时, dataToDisplay 没有第二个对象,并且您的应用程序正在崩溃。我不认为你应该在这里使用数组。既然您已经知道了单元格的数量,请手动将 numberOfRowsInSection:返回为10.而不是数组对象,请保持状态对象。然后在 tableView:cellForRowAtIndexPath:中,使用switch语句为单元格赋值。从我看到的,你可以摆脱 dataToDisplay 。
You are adding a single instance of Status in dataToDisplay. So when the second row is requested, dataToDisplay has no second object and your application is crashing. I don't think you should be using an array here. Since you know the number of cells already, manually return the numberOfRowsInSection: as 10. Instead of the array object, hold on to the Status object. Then in tableView:cellForRowAtIndexPath:, use the switch statement to assign values to the cell. From what I see, you can get rid of dataToDisplay.
更多推荐
将一个对象的属性放在不同的行中
发布评论