0

I'm trying to implements this library without using storyBoard (first step for implementing this library) , because I'm creating my UIcollectionView programmatically.

    - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];

    [_collectionView registerNib:[UINib nibWithNibName:@"myCell" bundle:nil] forCellWithReuseIdentifier:@"cell3"];
    [_collectionView setBackgroundColor:[UIColor colorWithRed:0.945 green:0.945 blue:0.945 alpha:1] ];
    [_collectionView setTransform:CGAffineTransformMakeScale(-1, 1)];

    RFQuiltLayout* layout = (id)[_collectionView collectionViewLayout];
    layout.direction = UICollectionViewScrollDirectionVertical;
    layout.blockPixels = CGSizeMake(100, 100);
}


- (UICollectionView *)collectionView {
    if (!_collectionView) {
        CGRect collectionViewFrame = self.view.bounds;
        collectionViewFrame.size.height -= (self.navigationController.viewControllers.count > 1 ? 0 : (CGRectGetHeight(self.tabBarController.tabBar.bounds))) + 0;
        //        FMMosaicLayout *mosaicLayout = [[FMMosaicLayout alloc] init];
        ////        _collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:mosaicLayout];
//                RFQuiltLayout* layout = (id)[_collectionView collectionViewLayout];
//                layout.direction = UICollectionViewScrollDirectionVertical;
//                layout.blockPixels = CGSizeMake(100, 100);
        _collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:[[RFQuiltLayout alloc] init]];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;

    }
    return _collectionView;
}

But this didn't worked and nothing is shown in my view (no error and empty view that's all) Also using debugger I've notified that the UICollectionView Method are never called

1 Answer 1

1

First of all, your collectionView method is not called because you are using _collectionView instead self.collectionView in your viewDidLoad method. You need to write self for every property to call their setter and getter methods.

Second, if you want to add custom layout without Storyboard of XIB, then you need to set it programmatically:

RFQuiltLayout* layout = [[RFQuiltLayout alloc] init];
layout.direction = UICollectionViewScrollDirectionVertical;
layout.blockPixels = CGSizeMake(100, 100);
self.collectionView.collectionViewLayout = layout;
Sign up to request clarification or add additional context in comments.

6 Comments

Nope this didn't help and always some issue I've changed my code in did load method like this but havn't worked. It's not an issue of SELF keyword I think
@Chlebta yeah, I just saw that you call SELF at adding subview... What property did you define for collectionView?
Yeah didn't worked , with this same code if i use in the (UicollectionView ) another costum layout like* FMMosaicLayout ** the commented code and i remove the RFQuiltLayout relatés code from viewDidLoad it works fine
Normally it´s strong, default value! What prop should I use ?
Must admit, very strange behavior. I still can not get why collectionView method is never called? I do not see any problems with this part of code, maybe problem occurs somewhere else in your project.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.