objective c - Error when adding Supplementary Header View to UICollectionView -
i getting following error implementing supplementary header view
terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'no uicollectionviewlayoutattributes instance -layoutattributesforsupplementaryelementofkind: headerview @ path <nsindexpath: 0x9e82a40> {length = 2, path = 0 - 0}' this code creating header view
- (uicollectionreusableview *)collectionview:(uicollectionview *)collectionview viewforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath { static nsstring * headeridentifier = @"headerview"; uicollectionreusableview *header = [collectionview dequeuereusablesupplementaryviewofkind:headeridentifier withreuseidentifier:uicollectionelementkindsectionheader forindexpath:indexpath]; return header; } the error happens in dequeuereusablesupplementaryviewofkind method.
i have added these 2 lines in initwithcoder of collection view controller
uinib *headernib = [uinib nibwithnibname:@"mtcollectionheaderview" bundle:nil]; [self.collectionview registernib:headernib forsupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:@"headerview"]; so have reference ui element. cannot find anyway set layout on header.
i tried adding same collection view controller never hit code confirmed putting debugger there
- (uicollectionviewlayoutattributes *)layoutattributesforsupplementaryelementofkind:(nsstring *)kind atindexpath:(nsindexpath *)indexpath { return [self.collectionviewlayout layoutattributesfordecorationviewofkind:kind atindexpath:indexpath]; } has seen issue , how did resolve it. using xcode 5 developer preview 5 , developing ios7
i believe passing headeridentifier kind of supplementary view , kind constant header identifier. try switching them shown in line of code in collectionview:viewforsupplementaryelementofkind:atindexpath: method:
uicollectionreusableview *header = [collectionview dequeuereusablesupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:headeridentifier forindexpath:indexpath]; i not think need implementation of layoutattributesforsupplementaryelementofkind:atindexpath:, swap above line of code in , see if works.
Comments
Post a Comment