【发布时间】:2011-10-09 10:56:56
【问题描述】:
这个 fetch 方法完美运行,NSLog 打印出数据库的内容...(在 NSArray 中获取对象):
NSError *error2;
fetchedObjects = [moc executeFetchRequest:fetchRequest error:&error2];
if (!fetchedObjects) {
NSLog(@"Error %@",[error2 localizedDescription]);
}
for (NSManagedObject *info in fetchedObjects) {
NSLog(@"Name: %@", [info valueForKey:@"Name"]);
NSLog(@"Description: %@", [info valueForKey:@"Description"]);
NSLog(@"Ingredients: %@", [info valueForKey:@"Ingredients"]);
.. 但是当我尝试填充 tableView 时(我已经构建了许多表,并且觉得我对它们的工作方式有很好的理解),程序在 int retVal = UIApplicationMain(argc, argv, nil 时出现“EXE_BAD_ACCESS”崩溃,无);。”就是这样,没有其他错误信息。
为了尝试调试,我将这个简单的 NSLog 放在“cellForRowAtIndexPath”方法中,但它在 NSLog(@"fetchedObjects count in tableview %i",[fetchedObjects count]) 处崩溃。
据我所知,我还没有发布数组。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSLog(@"fetchedObjects count in tableview %i",[fetchedObjects count]);
NSManagedObject *info3 = [fetchedObjects objectAtIndex:indexPath.row];
NSLog(@"Name: %@", [info3 valueForKey:@"Name"]);
cell.textLabel.text = [info3 valueForKey:@"Name"];
【问题讨论】:
-
numberOfRowsInSection 中的行数是多少?您在哪种方法中初始化 fetchedObjects?
-
嗨普拉文。我使用
return [ArrayNameHere count];目前是27。这意味着数组在那里......!?!
标签: iphone uitableview core-data nsmanagedobject