fetchedResultsController objectAtIndexPath:i“传递objectAtIndexPath的参数1:从整数中生成指针而不进行强制转换

时间:2010-12-31 11:40:28

标签: iphone objective-c

NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
 id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0];

 for (int i; i<[sectionInfo numberOfObjects]; i++) {
  NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i];
  [dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"];
  [dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"];
 }

在这一行

NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i];

我收到此警告:

warning: passing argument 1 of 'objectAtIndexPath:' makes pointer from integer without a cast

1 个答案:

答案 0 :(得分:4)

objectAtIndexPath:需要NSIndexPath个对象。您传递的是一个不正确的整数。

您需要为给定的行和段索引创建索引路径,然后将其传入。我不知道您是如何获取托管对象的,但我只假设每个部分有一行。如果是这种情况,请执行此操作以获取其部分中的每个托管对象:

// It's also a good idea to initialize i in your loop and not just declare it
for (int i = 0; i<[sectionInfo numberOfObjects]; i++) {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
    NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:indexPath];

    [dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"];
    [dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"];
}