我有一個JSON文件,我需要從中提取值並顯示在我的tableview中。一切正常。從JSON文件向Cell添加值 - 提供的代碼
{
"1": {
"name": "Jemmy",
"birthday": "1994-11-23"
},
"2": {
"name": "Sarah",
"birthday": "1994-04-12"
},
"3": {
"name": "Deb",
"birthday": "1994-11-23"
},
"4": {
"name": "Sam",
"birthday": "1994-11-23"
}
}
當我顯示的值,它不顯示在記錄中給出的1,2,3,4的順序。它只是隨機顯示。我在下面包含了我的代碼,我需要修改它,以便我可以按上面給出的順序顯示內容。有人可以幫忙嗎?
- (void)requestSuccessfullyCompleted:(ASIHTTPRequest *)request{
NSString *responseString = [request responseString];
SBJsonParser *parser = [SBJsonParser new];
id content = [responseString JSONValue];
if(!content){
return;
}
NSDictionary *personDictionary = content;
NSMutableArray *personMutableArray = [[NSMutableArray alloc] init];
for (NSDictionary *childDictionary in personDictionary.allValues)
{
Deal *deal = [[Deal alloc] init];
deal.name=[childDictionary objectForKey:@"name"];
deal.dob=[childDictionary objectForKey:@"birthday"];
[personMutableArray addObject:deal];
}
self.personArray = [NSArray arrayWithArray:personMutableArray];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
Person *person = [self.personArray objectAtIndex:indexPath.row];
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
cell.namelabel.text=person.name;
cell.doblabel.text=person.dob;
}
return cell;
}
我正在使用ARC。如果我在if條件之外添加'cell.namelabel'和'cell.doblabel'(如你所示),那麼當我滾動時單元格會重疊。我怎樣才能避免這種情況? – shajem 2012-02-01 01:36:57
你是什麼意思「重疊?」你正確設置你的細胞高度嗎?你如何實現Cell的繪圖? – 2012-02-01 14:18:13