我正在創建一個Ipad應用程序,它將充當酒單。計數numberOfRowsInSection根據部分
我的酒單是按部分組織的,每一部分都有不同數量的行。
我的問題是,我沒有設法根據部分計算行數。
我解析此JSON文件:
{"posts":[{"appellation":"Bordeaux Sup\u00e9rieur","nom":"Chateau David Beaulieu","annee":"2008","prix":"25"},{"appellation":"Blaye","nom":"Chateau L'Embrun","annee":"2006","prix":"35"},{"appellation":"Moulis","nom":"Ch\u00e2teau Poujeaux","annee":"1990","prix":"75"},{"appellation":"Moulis","nom":"Ch\u00e2teau Chasse-Spleen","annee":"1990","prix":"80"}]}
通常我應該有2排的部分「慕里斯」和一排的人。 我想其中的幾個解決方案:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSString *appellation=[[self.rows objectAtIndex:section] objectForKey:@"appellation"];
NSLog(@"appellation: %@",appellation);
NSArray *cpt=[dict objectForKey:appellation];
NSLog(@"cpt: %@",cpt);
return [cpt count];
}
返回
2011-05-03 13:49:12.947 cha[9913:207] appellation: Moulis
2011-05-03 13:49:12.947 cha[9913:207] cpt: (null)
2011-05-03 13:49:12.948 cha[9913:207] appellation: Bordeaux Supérieur
2011-05-03 13:49:12.949 cha[9913:207] cpt: (null)
2011-05-03 13:49:12.951 cha[9913:207] appellation: Blaye
2011-05-03 13:49:12.952 cha[9913:207] cpt: (null)
它返回好的部分,但不是好線。
的NSLog(@ 「字典%@」,字典)返回
2011-05-06 10:13:56.835 chan[2751:207] dict {
posts = (
{
annee = 2008;
appellation = "Bordeaux Sup\U00e9rieur";
nom = "Chateau David Beaulieu";
prix = 25;
},
{
annee = 2006;
appellation = Blaye;
nom = "Chateau L'Embrun";
prix = 35;
},
{
annee = 1990;
appellation = Moulis;
nom = "Chateau Poujeaux";
prix = 75;
},
{
annee = 1990;
appellation = Moulis;
nom = "Chateau Chasse Spleen";
prix = 80;
);
}
此代碼的工作完美,但現在我想我的按字母順序排列的酒單。我的字典是按字母順序創建的。我這allKeys排序結果隨機文檔中看到的,所以我用:
[[[appDelegate.mutableDic allKeys]sortedArrayUsingSelector:@selector(compare:)] objectAtIndex:section];
在viewForHeaderInSection
,並
NSDictionary *ligneVin;
ligneVin=[[[appDelegate.mutableDic allValues ] objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
中的cellForRowAtIndexPath
,但葡萄酒不符合任何更多與部分。
任何形式的幫助都非常感謝。
謝謝;)
檢查內容在 – visakh7 2011-05-06 08:27:21