Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSFetchedResultsController在使用“0”时创建额外的空行=&引用;谓语_Iphone_Ios_Nsfetchedresultscontroller - Fatal编程技术网

Iphone NSFetchedResultsController在使用“0”时创建额外的空行=&引用;谓语

Iphone NSFetchedResultsController在使用“0”时创建额外的空行=&引用;谓语,iphone,ios,nsfetchedresultscontroller,Iphone,Ios,Nsfetchedresultscontroller,我有一个UITableViewController,它由NSFetchedResultsController填充。我的CoreData实体有一个名为“submitter_id”的属性。根据控制器的初始化方式,我希望获取与给定提交者id匹配或与所述提交者id不匹配的记录。“does match”案例工作正常,但“Not match”案例有问题。我的sqlite db是正确的,但是我在TableView中得到了额外的空行 在下面的输出中,我从核心数据中获得了正确的3条记录,但是NSFetchedRe

我有一个UITableViewController,它由NSFetchedResultsController填充。我的CoreData实体有一个名为“submitter_id”的属性。根据控制器的初始化方式,我希望获取与给定提交者id匹配或与所述提交者id不匹配的记录。“does match”案例工作正常,但“Not match”案例有问题。我的sqlite db是正确的,但是我在TableView中得到了额外的空行

在下面的输出中,我从核心数据中获得了正确的3条记录,但是NSFetchedResultsController(或其他人)又向我的TableView添加了34个空行。注意:空行的数量遵循一种模式,这可能是一个线索:如果我删除应用程序并从头开始,我首先得到17个空行+3个好行。当我第二次运行它时,我得到34个空行+3个好行。从那时起,它稳定在34个空行。有趣的是,我的测试数据集中有17条记录

2011-03-25 15:35:17.256 test[54095:207] CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDELETED, t0.ZDESCRIPTION, t0.ZITEMID, t0.ZICON, t0.ZAVG, t0.ZNAME, t0.ZCREATIONDATE, t0.ZIMAGE, t0.ZSUBMITTERID, t0.ZUSER FROM ZITEM t0 WHERE  t0.ZSUBMITTERID <> ? ORDER BY t0.ZNAME DESC
2011-03-25 15:35:17.257 test[54095:207] CoreData: details: SQLite bind[0] = 32
2011-03-25 15:35:17.258 test[54095:207] CoreData: annotation: sql connection fetch time: 0.0017s
2011-03-25 15:35:17.258 test[54095:207] CoreData: annotation: fetch using <NSSQLiteStatement: 0x5f920f0> returned 3 rows with values: (
    "Plastic ballpoint",
    "Walmart readers",
    Blue
)
2011-03-25 15:35:17.263 test[54095:207] CoreData: annotation: total fetch execution time: 0.0071s for 3 rows.
2011-03-25 15:35:17.264 test[54095:207] numberOfSectionsInTableView: 1
2011-03-25 15:35:17.264 test[54095:207] numberOfRowsInSection 0: 37
2011-03-25 15:35:17.265 test[54095:207] indexPath 0
2011-03-25 15:35:17.268 test[54095:207] name: pen
2011-03-25 15:35:17.268 test[54095:207] indexPath 1
2011-03-25 15:35:17.269 test[54095:207] name: glasses
2011-03-25 15:35:17.269 test[54095:207] indexPath 2
2011-03-25 15:35:17.270 test[54095:207] name: checkbook
2011-03-25 15:35:17.270 test[54095:207] indexPath 3
2011-03-25 15:35:17.272 test[54095:207] name: (null)
2011-03-25 15:35:17.273 test[54095:207] indexPath 4
2011-03-25 15:35:17.275 test[54095:207] name: (null)
2011-03-25 15:35:17.275 test[54095:207] indexPath 5
2011-03-25 15:35:17.275 test[54095:207] name: (null)
2011-03-25 15:35:17.278 test[54095:207] indexPath 6
2011-03-25 15:35:17.279 test[54095:207] name: (null)
2011-03-25 15:35:17.279 test[54095:207] indexPath 7
2011-03-25 15:35:17.280 test[54095:207] name: (null)
2011-03-25 15:35:17.281 test[54095:207] indexPath 8
2011-03-25 15:35:17.281 test[54095:207] name: (null)
这里是我格式化单元格的地方:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForManagedObject:(NSManagedObject *)managedObject
{
    static NSString *CellIdentifier;
    if (self.listType == MY_ITEMS_LIST) {
        CellIdentifier = @"RSMyItemCell";
    }
    else {
        CellIdentifier = @"RSTBDItemCell";
    }

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...
    CDItem *item = (CDItem *)managedObject;
    cell.textLabel.text = item.name;
    cell.detailTextLabel.text = item.description;
    NSLog(@"name: %@",item.name);
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    NSInteger n = [sectionInfo numberOfObjects];
    NSLog(@"numberOfRowsInSection %d: %d",section,n);
    return n;
}
-(UITableViewCell*)表格视图:(UITableView*)表格视图cellForManagedObject:(NSManagedObject*)managedObject
{
静态NSString*CellIdentifier;
if(self.listType==我的项目列表){
CellIdentifier=@“RSMyItemCell”;
}
否则{
CellIdentifier=@“RSTBDItemCell”;
}
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]自动释放];
}
//配置单元格。。。
CDItem*item=(CDItem*)managedObject;
cell.textlab.text=item.name;
cell.detailTextLabel.text=item.description;
NSLog(@“名称:%@”,item.name);
返回单元;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节{
//返回节中的行数。
id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section];
NSInteger n=[sectionInfo numberOfObjects];
NSLog(@“第%d节中的行数:%d”,第,n节);
返回n;
}
我肯定我遗漏了一些东西,但我很难进一步调试它。有人见过这个吗?如果您想查看任何其他代码片段,请告诉我

谢谢


斯图

有时候,一个清醒的头脑就是所需要的。周末回来后,我看到了问题所在。以下是发生的情况供您参考:

在应用程序启动时,我使用从服务器下载的项目列表更新CoreData数据库。在尝试添加某个给定项之前,我会检查该项是否已存在于CoreData中。问题是我在打电话

[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]
在执行我的生存检查之前。这导致创建的实体没有相应的托管对象。即使CoreData将正确的数据集返回给NSFetchedResultsController,控制器也必须使用实体计数来确定
[sectionInfo numberOfObjects]

在任何情况下,将
insertNewObjectForEntityForName
调用移动到“不存在”子句中(其中
addObject
发生)都可以解决问题

谢谢


stu

您的
-tableView:numberOfRowsInSection:
的实现是什么样子的?
[NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext:]