Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        3年前关闭。
                                                                                            
                
        
我有一个响应如下的应用程序:

{
    "16-06-2016" = (
        {
            cccc = 16;
            dddd = 17;
        }
    );
    "17-06-2016" = (
        {
            cccc = 14;
            dddd = 19;
        },
        {
            cccc = 1;
            dddd = 9;
        }
    );
    "18-06-2016" = (
        {
            cccc = 14;
            dddd = 19;
        },
        {
            cccc = 1;
            dddd = 9;
        }
    );
}


如何在NSDictionary中显示此UITableView。有谁能够帮助我?

最佳答案

试试这个

self.sectionArr = [jsonDic allKeys]; //First get all section from dictionary like this


现在实现TableView委托方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return self.sectionArr.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
     return [self.sectionArr objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     NSArray *arr = [jsonDic objectForKey:[self.sectionArr objectAtIndex:section]];
     return arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     UITableViewCell *cell= [tableview dequeueReusableCellWithIdentifier:@"Cell"];
     NSArray *arr = [jsonDic objectForKey:[self.sectionArr objectAtIndex:indexPath.section]];
     cell.textLabel.text = [[arr objectAtIndex:indexPath.row] valueForKey:@"dddd"];
     return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSArray *arr = [jsonDic objectForKey:[self.sectionArr objectAtIndex:indexPath.section]];
     NSLog(@"Selected Obj - %@",[[arr objectAtIndex:indexPath.row] valueForKey:@"dddd"]);
}


希望这会帮助你。

关于ios - 如何从IOS中的NSDictionary加载tableView? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37991387/

10-12 22:13