小编Tyl*_*230的帖子

同时移动和更新UITableViewCell和NSFetchedResultsController

我有一个简单的表视图,包含1个部分和2个行.我正在使用a NSFetchedResultsController来保持表与CoreData同步.我对CD中的一行进行了更改,触发了一个要更新和移动的表视图单元格.问题是,当cellForRowAtIndexPath:在调用期间调用时NSFetchedResultsChangeUpdate,返回错误的单元格(这有意义b/c单元格尚未移动).因此,使用新更新的数据更新了错误的单元格.之后NSFetchedResultsChangeMove处理消息,以便单元格交换位置(单元格的内容都不会更新,因为它只是一个移动调用).结果是两个单元都反映了来自新更新的CD实体的数据.重新加载表可以解决问题.我正在运行iOS 6.换句话说,如果索引0处的单元格表示实体A而索引1表示实体B,并且我将实体A更新为A',使得2个单元格的顺序颠倒,结果就是我看到0:A'1:A,当我期望0:B,1:A'时.

- (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:
//the wrong cell is updated here
            [self configureCell:(SyncCell*)[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;

        case NSFetchedResultsChangeMove:
            [tableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
//this code produces errors too
            //[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            //[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)

uitableview nsfetchedresultscontroller ios ios6

6
推荐指数
2
解决办法
3630
查看次数

如何在开发过程中从xcode托管按需资源

我正在尝试为我的iOS应用程序实现按需资源下载.这些文件暗示了xcode可以在开发过程中为您托管资产包.我的问题是如何启用它?是否有另一种方法可以在开发期间测试按需资源下载."产品包中的嵌入资产包"构建设置是否相关?这里是docs:on demand docs中提到的xcode托管的地方

ios xcode7 on-demand-resources

5
推荐指数
2
解决办法
1512
查看次数

如何使用GLKMathUnproject

我使用GLKit创建了一个简单的3D世界.我正在尝试根据屏幕点击在我的3D世界中找到一个特定的点.看来我想要使用GLKMathUnproject.该方法的签名是:

GLKVector3 GLKMathUnproject (
   GLKVector3 window,
   GLKMatrix4 model,
   GLKMatrix4 projection,
   int *viewport,
   bool *success
);
Run Code Online (Sandbox Code Playgroud)

有些事情让我对它需要的参数感到困惑.首先不应该窗口坐标是GLKVector2?最重要的是,不会将屏幕上的点投射到3D空间中而是创建光线而不是单个点.当您将3D空间中的点投影到2D平面(也称为屏幕)上时,您会丢失关于该点的一维信息.那么如何才能将2D屏幕点转换为3D世界点,而无需指定您希望"取消投射"您的观点的深度?在互联网上的任何地方都没有关于这种方法的评论(除了苹果文档).

linear-algebra ios glkit

3
推荐指数
1
解决办法
1732
查看次数

从具有objective-c类别的类扩展协议

这是我想要做的:

id<MyDelegate> _delegate;
....
[_delegate performSelectorOnMainThread...]

@protocol MyDelegate <NSObject>
....
Run Code Online (Sandbox Code Playgroud)

我的问题是performSelectorOnMainThread是在NSObject类别中定义的,因此编译器无法识别它.我得到:"警告:' - performSelectorOnMainThread:withObject:waitUntilDone:'在协议中找不到'"我可以委托代表,但这会破坏代表的目的.有什么建议?

protocols objective-c categories

2
推荐指数
1
解决办法
450
查看次数