我使用一个函数来填充字典一个阵列 在这里是在上面的代码阵列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