简体   繁体   English

从JSON NSDictionary创建深入细节UITableView

[英]Creating Drill-Down Detail UITableView from JSON NSDictionary

I'm have a load of trouble finding out how to do this, 我在寻找方法上遇到了很多麻烦,

I want to show this in a UITableDetailView (Drill-Down style) with each item in a different cell. 我想在UITableDetailView(向下钻取样式)中显示此内容,并在不同的单元格中显示每个项目。 All of the things I've read all show how to load a single image on the detail instead of showing as a UITableView. 我读过的所有内容都显示了如何在细节上加载单个图像,而不是显示为UITableView。 Does the dictionary have to have "children" in order to load correctly? 字典是否必须有“孩子”才能正确加载? Here is the code for the first view creating *dict from the JSON rowsArray. 这是从JSON rowsArray创建* dict的第一个视图的代码。

I guess what I'm looking for is what to put in the FollowingDetailViewController.m to see the rest of *dict contents, so when selecting a row, it loads the rest of the *dict. 我想我要寻找的是放在FollowDetailDetailViewController.m中的内容,以查看* dict的其余内容,因此在选择一行时,它将加载* dict的其余内容。

I have rowsArray coming back as follows: 我有rowsArray返回如下:

'{ loginName = Johnson; '{loginName = Johnson;

memberid = 39; 会员编号= 39;

name = Kris; 名字= Kris;

age = ;}, etc,etc... 年龄=;}等,等等...

Thanks, 谢谢,

// SET UP TABLE & CELLS //设置表格和单元格

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
    NSDictionary *dict = [rowsArray objectAtIndex: indexPath.row];

    cell.textLabel.text = [dict objectForKey:@"name"];
    cell.detailTextLabel.text = [dict objectForKey:@"loginName"];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    return cell;
}

- (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];



- (void)viewDidLoad {
    [super viewDidLoad];

//GET JSON FROM WEBSERVICES:
    NSURL *url = [NSURL URLWithString:@"http://10.0.1.8/~imac/iphone/jsontest.php"];
    NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];

    NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;

    NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
    if (dict)
    {
        rowsArray = [dict objectForKey:@"member"];
        [rowsArray retain];
    }


[jsonreturn release];

}

//GO  TO DETAIL VIEW:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    FollowingDetailViewController *aFollowDetail = [[FollowingDetailViewController alloc] initWithNibName:@"FollowingDetailView" bundle:nil];
    [self.navigationController pushViewController:aFollowDetail animated:YES];
}

Don't use a blocking call to retrieve the JSON. 不要使用阻塞调用来检索JSON。 If your network is slow your app will hang. 如果您的网络速度很慢,您的应用将挂起。 You should use an async method to retrieve the data. 您应该使用异步方法来检索数据。

Look into loading the JSON contents into a model object. 研究将JSON内容加载到模型对象中。 Then use an array of models to power your tableview. 然后使用一系列模型来增强您的表视图。 DidSelectRowAtIndexPath could then pass a instance of model object into your detail view either through a custom initializer or by setting a property after you alloc/init it. 然后,DidSelectRowAtIndexPath可以通过自定义初始化程序或通过在分配/初始化之后设置属性来将模型对象的实例传递到详细信息视图中。 Your question is pretty hard to parse so I'm not sure if I'm addressing what you are after. 您的问题很难解析,因此我不确定是否要解决您的问题。 Take a look at the numerous samples for table view UI hierarchies on the developer site. 查看开发人员站点上用于表视图UI层次结构的众多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM