我使用一個函數來填充字典一個陣列 在這裏是在上面的代碼陣列flashcardsNamesList,flashCardsId調用函數[自getFlashCard當改變每次代碼如何從iPhone中的nsdictionary檢索值?
-(void)getAllFlashCardsNames
{
if ([listofitems count]==0)
listofitems = [[NSMutableArray alloc] init];
else
[listofitems removeAllObjects];
for(int i=0;i<listOfCategoryId.count;i++)
{
int j=[[listOfCategoryId objectAtIndex:i]intValue];
[self getFlashCard:j];
NSArray *flashCardsNames = flashCardsNamesList;
NSArray *flashCardsids = flashCardsId;
NSLog(@"FLash Card Ids %@",flashCardsids);
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:flashCardsNames,@"flashCards",flashCardsids,@"flashCardId",nil];
[listofitems addObject:dictionary];
}
}
:J- ]。 j是改變來自listOfCategoryId數組的categoryid的參數。
現在如何從字典中檢索值我想在uitableview的不同部分顯示不同的flashcardsNames。
這裏是代碼即時通訊使用檢索值
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [listofitems count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
NSDictionary *dictionary =[listofitems objectAtIndex:section];
NSLog(@"dictionary=%@",dictionary);
NSArray *array =[dictionary objectForKey:@"flashCards"];
NSLog(@"array=%@",array);
NSLog(@"Section Count = %d",array.count);
return array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *dictionary =[listofitems objectAtIndex:indexPath.section];
NSArray *array =[dictionary objectForKey:@"flashCards"];
NSArray *array1=[dictionary objectForKey:@"flashCardId"];
NSString *cellValue=[array objectAtIndex:indexPath.row];
NSString *cellValue1=[array1 objectAtIndex:indexPath.row];
[cell.FlashCardsNames setText:cellValue];
[cell setFlashCardId:[cellValue1 intValue]];
return cell;
}
但該方法 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
不會被調用
您是否將您的方法實現的對象設置爲表視圖的數據源? 這是什麼意思? – 2009-06-14 17:20:06