ios - Adding UICollectionViewLayout programmatically issue -
i'm trying implements this library without using storyboard (first step implementing library) , because i'm creating uicollectionview programmatically.
- (void)viewdidload { [super viewdidload]; // additional setup after loading 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 didn't worked , nothing shown in view (no error , empty view that's all) using debugger i've notified uicollectionview method never called
first of all, collectionview method not called because using _collectionview instead self.collectionview in viewdidload method. need write self every property call setter , getter methods.
second, if want add custom layout without storyboard of xib, need set programmatically:
rfquiltlayout* layout = [[rfquiltlayout alloc] init]; layout.direction = uicollectionviewscrolldirectionvertical; layout.blockpixels = cgsizemake(100, 100); self.collectionview.collectionviewlayout = layout;
Comments
Post a Comment