如何在iphone中从nsdictionary检索值?
我正在使用一个函数来填充数组中的字典 这是密码如何在iphone中从nsdictionary检索值?,iphone,objective-c,Iphone,Objective C,我正在使用一个函数来填充数组中的字典 这是密码 -(void)getAllFlashCardsNames { if ([listofitems count]==0) listofitems = [[NSMutableArray alloc] init]; else [listofitems removeAllObjects]; for(int i=0;i<listOfCategoryId.count;i++) { int j=[[listOfCat
-(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];
}
}
但是方法
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
未被调用
但是没有调用方法-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
您是否将实现方法的对象设置为表视图的数据源
UITableView
将部分工作交给另一个对象,该对象必须符合UITableViewDataSource
和UITableViewDelegate
协议;然后必须在IB中或以编程方式将对象设置为表视图的数据源
和委托
(数据源和委托可以是不同的对象,但通常是相同的对象)。看看哪一个更能解释它;完成此操作后,对象必须处理tableView:cellforrowatinexpath:
和tableView:numberofrowsinssection:
方法,表视图将对对象调用这些方法
此外,行:
if ([listofitems count]==0)
listofitems = [[NSMutableArray alloc] init];
没有道理。我假设您正在检查数组是否已分配,如果未分配,则分配它。如果尚未分配数组,它将为nil
,因此向其发送count
将不会产生任何效果。如果它以前已分配,但已解除分配但未恢复为nil
,则它将是一个错误的指针,并导致应用程序崩溃
更好的分配方法是在类的awakeFromNib
方法中分配,或者applicationdFinishLaunching:
方法中分配,如果您在uiapplicationLegate
子类中实现它的话。别忘了在dealloc
方法中释放它
但是没有调用方法-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
您是否将实现方法的对象设置为表视图的数据源
UITableView
将部分工作交给另一个对象,该对象必须符合UITableViewDataSource
和UITableViewDelegate
协议;然后必须在IB中或以编程方式将对象设置为表视图的数据源
和委托
(数据源和委托可以是不同的对象,但通常是相同的对象)。看看哪一个更能解释它;完成此操作后,对象必须处理tableView:cellforrowatinexpath:
和tableView:numberofrowsinssection:
方法,表视图将对对象调用这些方法
此外,行:
if ([listofitems count]==0)
listofitems = [[NSMutableArray alloc] init];
没有道理。我假设您正在检查数组是否已分配,如果未分配,则分配它。如果尚未分配数组,它将为nil
,因此向其发送count
将不会产生任何效果。如果它以前已分配,但已解除分配但未恢复为nil
,则它将是一个错误的指针,并导致应用程序崩溃
更好的分配方法是在类的
awakeFromNib
方法中分配,或者applicationdFinishLaunching:
方法中分配,如果您在uiapplicationLegate
子类中实现它的话。不要忘记在您的dealloc
方法中释放它。您是否将实现方法的对象设置为表视图的数据源?这意味着什么???调用了方法tableView:numberOfRowsInSection:method,但此行返回数组NSArray*数组=[dictionary objectForKey:@“flashCards”]中的0个对象;我被困在这里..什么时候调用getAllFlashCardsNames,在NSArray*flashCardsNames=flashCardsNamesList行中;flashCsrdsNamesList
在哪里填充对象?flashCardsNamesList;这是从数据库生成的,我正在通过传递categoryid调用getAllFlashCardsNames方法来获取FlashCardSnames列表。类别id是从数据库生成的。您是否将实现方法的对象设置为表视图的数据源?这意味着什么???调用了方法tableView:numberOfRowsInSection:method,但此行返回数组NSArray*数组=[dictionary objectForKey:@“flashCards”]中的0个对象;我被困在这里..什么时候调用getAllFlashCardsNames,在NSArray*flashCardsNames=flashCardsNamesList行中;flashCsrdsNamesList
在哪里填充对象?flashCardsNamesList;这是从数据库生成的,我通过传递categoryid调用getAllFlashCardsNames方法来获取flashCardsNamesList.and category id是从数据库生成的
if ([listofitems count]==0)
listofitems = [[NSMutableArray alloc] init];