我目前非常简单地使用UICollectionViewFlowLayout:
UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake(75, 75);
flowLayout.minimumInteritemSpacing = 2;
flowLayout.minimumLineSpacing = 2;
_collectionView.collectionViewLayout = flowLayout;
Run Code Online (Sandbox Code Playgroud)
我有多个部分(来自不同来源的单元格),但是,我想以连续的方式渲染网格.因此,各部分之间不会有明显的中断.
请参阅屏幕截图,为了开发目的,我将在两个部分中呈现相同的单元格.
任何想法,我如何获得流程布局允许多个部分,但没有休息时间?
我UICollectionView
在我的应用程序中实现了一个.我的问题是我需要选择(如果用户点击它)一个单元格programmatically
.方法:
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath
animated:(BOOL)animated
scrollPosition:(UICollectionViewScrollPosition)scrollPosition
Run Code Online (Sandbox Code Playgroud)
这是UICollectionView
类的一部分不是我需要调用的,因为这个方法不会调用:
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
它只是将selected
单元格的属性设置为YES
;
我正在使用a UIMenuItem
在UICollectionView
单元长按中执行自定义操作.这与iOS 6完美配合,但现在我将我的应用程序转换为iOS 7和Xcode 5,但它无法正常工作.自定义项目未显示.
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Unfavorite"
action:@selector(unFavorite:)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:menuItem]];
[UIMenuController sharedMenuController].menuVisible = YES;
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender;
{
//do not show default itens like copy, paste....
[self becomeFirstResponder];
return NO;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
// The selector(s) should match your UIMenuItem selector
if (action == @selector(unFavorite:)) {
return YES;
}
return NO;
}
- (void)collectionView:(UICollectionView *)collectionView
performAction:(SEL)action
forItemAtIndexPath:(NSIndexPath *)indexPath
withSender:(id)sender {
}
- (BOOL)collectionView:(UICollectionView *)collectionView
shouldShowMenuForItemAtIndexPath:(NSIndexPath …
Run Code Online (Sandbox Code Playgroud) 我有一个视图,我从主要检索已保存的实体(路线*)NSManagedObjectContext
.我想将其导入到tempContext
.按照Marcus Zarra的例子,我这样做:
NSManagedObjectContext *moc = _route.managedObjectContext;
NSManagedObjectID *routeId = [_route objectID];
NSPersistentStoreCoordinator *psc = moc.persistentStoreCoordinator;
self.tempContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[self.tempContext setPersistentStoreCoordinator:psc];
NSManagedObject *localRoute = [self.tempContext objectWithID:routeId];
[localRoute moToDictionary:localRoute];
self.tempContext.parentContext = moc; // crashes here
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到我尝试将parentContext
我的tempContext
设置为主要的MOC.我收到错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Context already has a coordinator; cannot replace.'
Run Code Online (Sandbox Code Playgroud)
我明白它告诉我,我无法改变persistentStoreCoordinator
.但是,我不确定为什么它会告诉我.当我设置断点时,它tempContext
与主moc处于不同的内存地址.此外,self.tempContext.parentContext
是零.所以我认为如果它是零,我可以将nil参数设置为moc,但它会崩溃.有什么想法吗?提前致谢!