将数据从一个对象添加到 UITableView
我编写了这段代码,
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];
[self.tableView reloadData];
我想将结果状态对象放在表视图中,每个属性在一行(单元格)中。 我不知道该怎么做。我写了这个,但他们在同一行中显示了它们。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSLog(@"1 ok");
Status *statut2 = [dataToDisplay objectAtIndex:indexPath.row];
NSLog(@"2 ok");
cell.textLabel.text = [NSString stringWithFormat:@"%@%@",statut2.flyNumber,statut2.ftatuts];
NSLog(@"3 ok");
return cell;
请帮忙
i writed this code ,
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];
[self.tableView reloadData];
and i want to put the result statut object in a table view , each attribute in a line ( cell ) .
i don't know how to to . I writed this but they show them in the same line .
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSLog(@"1 ok");
Status *statut2 = [dataToDisplay objectAtIndex:indexPath.row];
NSLog(@"2 ok");
cell.textLabel.text = [NSString stringWithFormat:@"%@%@",statut2.flyNumber,statut2.ftatuts];
NSLog(@"3 ok");
return cell;
Help please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以让 Statut 类返回一个数组,其中包含您从 JSON 数据设置的所有属性。然后您可以简单地使用数组来设置行数和每行的单元格。
Maybe you could have your Statut class return an array containing all of the properties you set from your JSON data. Then you can simply use the array to set the number of rows and the cell for each row.
这是一个解决方案,允许您配置属性在 tableView 中显示的顺序:
在
-tableView:cellForRowAtIndexPath:
方法实现中:显然,
tableView:numberOfRowsInSection:
必须返回10
。Here is a solution that allows you to configure the order in which your attributes will appear in your tableView:
In your
-tableView:cellForRowAtIndexPath:
method implementation:Evidently,
tableView:numberOfRowsInSection:
must return10
.