将一个对象的属性放在不同的行中

编程入门 行业动态 更新时间:2024-10-09 00:51:20
本文介绍了将一个对象的属性放在不同的行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 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 .... 我试着遵循这个例子,

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.

更多推荐

将一个对象的属性放在不同的行中

本文发布于:2023-07-09 10:35:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   属性   对象

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!