相关疑难解决方法(0)

UICollectionView和Supplementary View(标题)

试图在我UICollectionView的标题中添加一个补充视图.我有问题让它工作.

我使用一个自定义UICollectionViewFlowLayout来返回一个contentSize总是至少比帧大1个像素(我使用的UIFreshControl只有UICollectionView滚动,并且设置collectionView.contentSize直接无效)并invalidateLayout打开sectionInsertitemSize更改:

-(void)setSectionInset:(UIEdgeInsets)sectionInset {
    if (UIEdgeInsetsEqualToEdgeInsets(super.sectionInset, sectionInset)) {
        return;
    }

    super.sectionInset = sectionInset;

    [self invalidateLayout];

}

-(void) setItemSize:(CGSize)itemSize {
    if (CGSizeEqualToSize(super.itemSize, itemSize)) {
        return;
    }

    super.itemSize = itemSize;

    [self invalidateLayout];
}

- (CGSize)collectionViewContentSize
{
    CGFloat height = [super collectionViewContentSize].height;

    // Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
    if (height < self.collectionView.bounds.size.height) {
        height = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewlayout

17
推荐指数
4
解决办法
6万
查看次数

如何以编程方式更改UICollectionView footerview的高度

我遇到一个问题,在我的UICollectionView中,我需要在返回的记录为0时显示一个页脚.下面的代码似乎工作正常,当没有记录时,会显示页脚.但是,有一个问题是,当有记录时,虽然页脚被隐藏,代码LINE 1似乎没有任何效果,这意味着页脚的空白区域仍然存在.知道怎么摆脱它吗?即将页脚高度更改为0,或者在返回记录时删除页脚.

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    CGSize footerSize = CGSizeMake(320, self.view.frame.size.height);
    return footerSize;
  }

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionFooter) {
        reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
        reusableview.hidden = YES;
        if([topicArray count]>0){
            reusableview.hidden = YES;
            //reusableview.frame = CGRectMake(0, 0, 0, 0);
            CGRect newFrame = reusableview.frame;
            newFrame.size.height =0;
            reusableview.frame = newFrame; // <-------- LINE 1.
        }else{
            reusableview.hidden = NO;
            reusableview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
            UIImageView *oopsImgView =[[UIImageView …
Run Code Online (Sandbox Code Playgroud)

uicollectionview uicollectionviewlayout

4
推荐指数
1
解决办法
9114
查看次数

UICollectionView和Supplementary View崩溃

我有一个UICollectioView工作正常.有两种方法可以访问此页面.

  1. 虽然应用程序.
  2. 点按推送通知.

除了一个案例,一切都很好.

如果用户在聊天中,然后他退出应用程序(主页按钮),那么他会得到推送通知,他按下它并且应用程序崩溃.

崩溃:

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)

ios uicollectionview swift

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