相关疑难解决方法(0)

dequeueReusableCellWithIdentifier:forIndexPath:的indexPath在哪里使用?

Apple的文档说明了indexPath参数:

索引路径指定单元格的位置.数据源在被要求提供单元格时会收到此信息,并且应该将其传递给它.此方法使用索引路径根据单元格在表视图中的位置执行其他配置.

register(Class|Nib):forCellReuseIdentifier:仅指定要使用的重用标识符,而不是指定段或一组索引路径.

我想也许UITableViewCell有一些方法可以把它放在索引路径上,所以如果在一个部分的第一行,它可以绕过它的角,但是我没有看到它.在创建时,它获得的只是它的样式和重用标识符(initWithStyle:reuseIdentifier:); 在重用时,所有它被告知是prepareForReuse.

看到旧dequeueReusableCellWithIdentifier:的仍然受到支持,如果它不能依赖有机会这样做,它可能会采取什么样的基于索引路径的配置呢?

我检查了表视图编程指南,但自iOS 5以来它没有更新.

uitableview ios ios6

40
推荐指数
2
解决办法
9383
查看次数

如何刷新UITableViewController或NSFetchedResultsController?

我的UITableViewController或NSFetchedResultsController有点问题.我不确定问题是什么,但我猜它是UITableViewController.

正如我所说的,我使用NSFetchedResultsController将我的数据填充到UITableViewController中.数据按日期排序,并按日期显示在各个部分,例如2010年5月/ 2010年6月/等.这显示为节标题.

现在,当我添加新数据时,它会自动使用当前日期作为默认值,但是如果我想使用日期,那当前不在部分列表中,例如2010年4月(目前列表中的5月和6月),那么这是没有正确显示.只有当我退出应用程序并再次启动它时,它才会显示新的部分标题,一切都很好.

所以我需要能够刷新我的列表或更新它.只需将其添加到上下文并更改它似乎不会更新它.

同样,我不知道我需要更新什么,如果它是我的NSFetchedResultsController对象或UITableViewController.

更新#1:

我只想到这个方法有一个例外:

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller 
{
    // The fetch controller has sent all current change notifications, so tell the table view to process all updates.
    [self.tableView endUpdates];

}
Run Code Online (Sandbox Code Playgroud)

这是我移动数据的地方:

- (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];
            // …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview nsfetchedresultscontroller

9
推荐指数
2
解决办法
2万
查看次数