【发布时间】:2012-11-17 20:05:47
【问题描述】:
我是 Objective C 编程新手
这是我的两难境地:我正在从网络中提取一个 JSON 文件,并且能够将其中一个元素 (currDate) 显示到我的 tableView 中,但现在我想显示更多。从下面的代码中,我可以让它同时显示 currDate 和 prevDate
这里需要改一下逻辑:
for (NSDictionary *diction in arrayOfEntry) {
NSString *currDate = [diction objectForKey:@"Current Date"];
a = currDate;
NSString *prevDate = [diction objectForKey:@"Previous Date"];
b = prevDate;
[array addObject:a];
}
[[self myTableView]reloadData];
我不确定是否需要在此处更改任何内容,但我将其附加以显示我如何将数组显示到我的 viewTable:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
//cell.textLabel.text = [array objectsAtIndexes:indexPath.row];
return cell;
}
【问题讨论】:
-
那个for循环sn-p实际上是在这个里面:-(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSDictionary *allDataDictionary = [NSJSONSerialization JSONObjectWithData:webData options:0 error:nil]; NSDictionary *feed= [allDataDictionary objectForKey:@"feed"]; NSArray *arrayOfEntry = [feed objectForKey:@"entry"]; ....for...blah blah blah
标签: objective-c ios json