我有两个部分UICollectionView.我想UICollectionView仅显示第1节中的节标题.不在第0部分.
于是,我就回nil以viewForSupplementaryElementOfKind:方法section == 0并返回查看的section == 1.
它崩溃并显示以下错误:
Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes]:
Run Code Online (Sandbox Code Playgroud)
这是补充视图的代码.
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *sectionHeader = nil;
if (kind == UICollectionElementKindSectionHeader && indexPath.section == 1) {
sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"EventSectionHeader" forIndexPath:indexPath];
sectionHeader.layer.borderWidth = .5f;
sectionHeader.layer.borderColor = [UIColor colorWithRed:221.0 / 255.0 green:223.0 / 255.0 blue:220.0 / 255.0 alpha:1.0].CGColor;
}
return sectionHeader;
}
Run Code Online (Sandbox Code Playgroud)
我发现在viewForSupplementaryElementOfKind:方法崩溃时也会返回nil .其他答案建议删除该方法.
但我想只显示特定部分的节标题.如何只为一个部分实现返回视图?谢谢.任何帮助,将不胜感激.
编辑:
正如@san所说,我已更新代码以隐藏节标题.有用.它隐藏了标题.但我仍然看到节标题处的空白空间.预期结果是如果隐藏了节标题,则应该没有空格. …
我有一个UICollectioView工作正常.有两种方法可以访问此页面.
除了一个案例,一切都很好.
如果用户在聊天中,然后他退出应用程序(主页按钮),那么他会得到推送通知,他按下它并且应用程序崩溃.
崩溃:
2015-09-25 10:28:15.140 Quest [298:16922] *断言失败 - [UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:],/ BuildRoot/Library/Cache/com.apple.xbs/Sources/UIKit/UIKit-3505.16/UICollectionView.m:1519 2015-09-25 10:28:15.146任务[298:16922]* 终止应用程序由于未捕获的异常 'NSInternalInconsistencyException',理由是: 'UICollectionView数据源未设置'***第一掷调用堆栈:(0x1828b4f5c 0x1973b7f80 0x1828b4e2c 0x1837a3f3c 0x187f97a38 0x187e6ebd4 0x187e6fb54 0x187e69b88 0x187e0700c 0x18760df14 0x187608b20 0x1876089e0 0x18760807c 0x187607dd0 0x1880c0bd4 0x18286c48c 0x18286bdc4 0x182869d4c 0x182798dc0 0x18d8ec088 0x187e72f60 0x100215590 0x197be28b8)libc ++ abi.dylib:以NSException类型的未捕获异常终止
推送处理程序中的代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let home = storyboard.instantiateViewControllerWithIdentifier("home") as! HomeViewController
let chat = storyboard.instantiateViewControllerWithIdentifier("chat") as! ChatViewController
var controllers : [UIViewController] = [login, chat]
NotificationManager.handleNotification(userInfo, controllers: &controllers, storyboard: storyboard)
navC.viewControllers = …Run Code Online (Sandbox Code Playgroud)