Ios 使用NSDictionary获取TableView
我认为这很简单,但我不能让它工作 我有一个文本字段,在这里我输入一个字符串。。。然后我将它发送到一个web服务 我获取JSON并解析它Ios 使用NSDictionary获取TableView,ios,xcode,Ios,Xcode,我认为这很简单,但我不能让它工作 我有一个文本字段,在这里我输入一个字符串。。。然后我将它发送到一个web服务 我获取JSON并解析它 - (void)requestFinished:(ASIHTTPRequest *)request // some code :::::: NSLog(@"OkRequest || %@ ", jsonDictionary); for (NSDictionary *ville in jsonDictionary) { NSString *titl
- (void)requestFinished:(ASIHTTPRequest *)request
// some code ::::::
NSLog(@"OkRequest || %@ ", jsonDictionary);
for (NSDictionary *ville in jsonDictionary)
{
NSString *title = [ville objectForKey:@"label"];
NSLog(@"%@", title);
}
我制作NSDictionary,但当我想将其设置为表视图时。。。我不知道如何将该字典发送到另一个方法。声明一个类成员
NSDictionary*\u jsonDict代码>
在requestFinished:
方法中,将值分配给类成员并保留该值。然后将表视图重新加载为[self.tableView reloadData]代码>
在cellforrowatinexpath:
方法中,从字典中获取值并将其设置为标签
更新:
- (void)requestFinished:(ASIHTTPRequest *)request
{
... some code
_jsonDict = [jsonDictionary retain];
[self.tableView reloadData];
}
jsonDictionary
是NSArray对象还是NSDictionary对象?它是一个NSMutableDictionary:NSMutableDictionary*jsonDictionary=[parser objectWithString:theJSON error:nil];是的,它是有效的。。。它返回这个。来源:NSLog(@“%@”,标题);Nancy,Lorraine,2012-04-19 12:33:30.137[15180:11603]Nantes,Pays de la LoireI在你说分配价值并保留价值时没有得到东西。。。对于重新加载表,两者都不适用。我想这是在另一个方法中?我想我需要的只是帮助了解这个类的价值。。。我不太明白…谢谢。。。所以,正如我所看到的。。。TableView需要这样的JSON:[{id:bla;lol:yeah;}]而不是像普通文本一样?我现在有了这个(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{return[\u jsonDict count];}-(NSInteger)tableView:(UITableView*)tableView:(NSInteger)numberofrowsinssection:(NSInteger)section{return 1;}-(UITableView cell*)tableView cell for rowatinexpath:(nsindepath*)indepath{static NSString*cell identifier=@“Cell;UITableViewCell*Cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];if(Cell==nil){Cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];Cell.textLabel.text=[\u jsonDict objectForKey:@“label”];//在此处设置单元格文本]return cell;}但我认为缺少了一些东西