English 中文(简体)
D. 了解国家扫盲基金会如何调整工作 主计长办公室
原标题:Understanding how NSFetchedResultsController works
  • 时间:2011-09-05 07:44:52
  •  标签:
  • iphone
  • ios

首先,如果你找到时间帮助我!

我一直在学习<代码>NSFettorResultsController,并尽量理解这一编号,不过,关于它的一些事情令我困惑不解。 这部法律如果从一个辅导单上找到。 基本上,我拥有最简单的手提控制器,采用像这种真正可行的方法建立起来。

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    // The fetch controller is about to start sending change notifications, so prepare the table view for updates.
    [self.tableView beginUpdates];
}


- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

    UITableView *tableView = self.tableView;

    switch(type) {

        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            // Reloading the section inserts a new row and ensures that titles are updated appropriately.
            [tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

 (NSFetchedResultsController *)fetchedResultsController {

    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription 
        entityForName:@"FailedBankInfo" inManagedObjectContext:_context];
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sort = [[NSSortDescriptor alloc] 
        initWithKey:@"details.closeDate" ascending:NO];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

    [fetchRequest setFetchBatchSize:20];

    NSFetchedResultsController *theFetchedResultsController = 
        [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
            managedObjectContext:_context sectionNameKeyPath:nil 
            cacheName:@"Root"];
    self.fetchedResultsController = theFetchedResultsController;
    _fetchedResultsController.delegate = self;

    [sort release];
    [fetchRequest release];
    [theFetchedResultsController release];

    return _fetchedResultsController;    

}
  1. 是否需要为不同观点的控制者每刻设立一个新的轮值控制员? 例如,如果在一份清单中有一份企业清单。 然后,我点击其中一名雇员,然后把我带至该镇的雇员名单,即必须使用不同的密码。 鉴于有必要重新确定实体的关键权利? 见上文我的执行。

  2. With my current implementation, it works great for listing items. Let s say I have a view controller called VC. init i fully implemented NSFetchedResultsController. I have a barbutton add item and a method called addButtonPressed which when pressed modally adds a view (from bottom up). In this same method i have Entity myEntity = [NSEntityDescription insertNNewObjectForEntityForName:@"Entity" inManagedObjectContext:context_]; Then i tell the code the go into another view. HOWEVER, when the animation is moving the new navigation controller up, the new cell already shows itself mid animation. From my understanding this these two methods - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath AND - (UITableViewCell *)tableView:(UITableView *)tableView get called in conjuction with the top two methods in the code snippet above. how can i fix it? i dont want anything showing up on the current view until i added a new Entity by going to another view. The second another object gets called into the context, the update methods must get called or something

  3. 这部法典做了些什么? 尤其是,有id和lt;有 st;有 st;有 st。

    (不含) 控制器(NSFetèreResultsController *)控制器确实设有: NSFetResults SectionInfoIndex:NSUInteger)Index forChangeType:NSFettorResultsChangeType 页: 1

    switch(type) {
    
        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    
        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
    

    } Edit: Holy $#$, formatting this frustrating. there should be didChangeSection:(id (LESS THAN EQUAL SIGN) NSFetchedResultsSectionInfo (GREATER THEN EQUAL SIGN)) in the code above

4) 我们可以更多地了解这一点。 i. 更新个人内容的方法是什么,何时使用。 国家扫盲基金会还是一个阵列吗? 说到,如果想与多个部门进行表象,则需要更多的眼光。 再次重申:

问题回答

我的第二点是布雷德评论,但我要向各位提出一些要点:

  1. 基本是,你们需要新的国家扫盲基金会。 您希望询问的每个实体的主计长。 然而,你不需要使用,国家扫盲基金会也没有配备人员。 完全是主计长,这只是一个ice子,让你在桌子上做ancy事。 你在问题2中的看法。

  2. Your problem here is that you are calling [NSEntityDescription insertNNewObjectForEntityForName:@"Entity" inManagedObjectContext:context_]; from your tableViewController and as soon as you call that your NSFetechedResultsController will get a message stating that a row was inserted, triggering the NSFetchedResultsChangeInsert path in your controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: method. NSFetchedResultsController is an object that watches the data that is fetches from CoreData for any changes and then gives you the ability to do stuff as the changes happen. To fix your display issue, just move the insertNewObjectForEntityName call into your next viewController, and magically when you dismiss that viewController you ll have a new row.

  3. The doChange Section: delegation methods of NSFettorResults 主计长正在通知你,如果在数据集中添加或删除一节的话。 见我对第4号的答复,这一点应当明确。

  4. NSFetechedResultsController allows you to "section" the data it fetches using the sectionNameKeyPath: part of the init call. By supplying the name of a data point in your entity you can group your data into sections. So going back to #3 & #2 if you happen to insert a new entity that has a new value in the "section" keypath that you specified when initing the NSFetchedResultsController you d get the didChangeSection: delegate called.

I recommend reading Apples documentation on NSFetchedResultsController and CoreData and probably their TableView Programming Guide. Don t forget to download and play with the sample code, it s easier to understand in most cases than the theories in the documentation.





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签