Recently the project tested a long-hidden bug, after many tests, found a custom Uicollectionviewcell under iOS9 only go once awakefromnib.
Specifically, there is a controller in the project that uses a custom Uicollectionview with four sets of data, whereas three sets of custom Uicollectionviewcell layouts and child controls are the same, so only two types of cells are registered
#import <UIKit/UIKit.h>@interface Yimaidoctorgroupmoretopiccollectionview: Uicollectionview+ (instancetype) Collectionviewwithobject: (ID)object; @end
#defineKcollectionviewheight 96.0#defineKcommonidentifier @ "Yimaidoctorgroupmoretopiccommoncollectioncell"#defineKmyidentifier @ "Yimaidoctorgroupmoretopicmycollectioncell"#import "YimaiDoctorGroupMoreTopicCollectionView.h"@implementationYimaidoctorgroupmoretopiccollectionviewStaticNSStringConst*commonidentifier =@"Yimaidoctorgroupmoretopiccommoncollectioncell";StaticNSStringConst*myidentifier =@"Yimaidoctorgroupmoretopicmycollectioncell";+ (Instancetype) Collectionviewwithobject: (ID)Object{ //Flow LayoutUicollectionviewflowlayout *layout =[[Uicollectionviewflowlayout alloc] init]; Layout.scrolldirection=Uicollectionviewscrolldirectionhorizontal; CGFloat itemheight= Kscreenh-kcollectionviewheight-Knavigtaionheight; Layout.itemsize=Cgsizemake (Kscreenw, itemheight); Layout.minimumlinespacing=0; Layout.minimuminteritemspacing=0; //InitializeYimaidoctorgroupmoretopiccollectionview *collection =[[Yimaidoctorgroupmoretopiccollectionview alloc] Initwithframe:cgrectzero collectionviewlayout:layout]; //Register [Collection registernib:[uinib nibwithnibname:kcommonidentifier Bundle:nil] Forcellwithreuseidentifier: Kcommonidentifier];[Collection registernib:[uinib nibwithnibname:kmyidentifier Bundle:nil] Forcellwithreuseidentifier: Kmyidentifier]; //page Outcollection.pagingenabled =YES; //data source, proxyCollection.Delegate=Object; Collection.datasource=Object; //Collection.backgroundcolor =[Uicolor Clearcolor]; returncollection;}@end
In the data source method of the owning controller, initialize and assign the value
#pragmamark-uicollectionviewdelegate-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) section{return 4;}-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{StaticNSString *identifier; if(Indexpath.item <3) {identifier=@"Yimaidoctorgroupmoretopiccommoncollectioncell"; Yimaidoctorgroupmoretopiccommoncollectioncell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath]; Cell.type= [NSString stringWithFormat:@"%ld", Indexpath.item +1]; FLOG (@"cell ========%@", cell); returncell; }Else{identifier=@"Yimaidoctorgroupmoretopicmycollectioncell"; Yimaidoctorgroupmoretopicmycollectioncell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath]; Cell.type= (int) Indexpath.item +1; returncell; }}
Each custom Uicollectionviewcell is added with UITableView as a child control and can be pulled up and loaded, and a drop-down is refreshed, so there are some initialization
#pragma mark-life cycle-(void) awakefromnib { [super awakefromnib]; // Set TableView [self settableviewattributes]; 1 ;}
The top of the current controller also has the qualify button, which can be clicked to achieve Uicollectionview sliding
Above is the core source code, seemingly very correct implementation, but finally verify the iOS9 under the "Can't Slide", that appears to be the following sentence does not execute
0) Animated:no];
Finally through a variety of system version of the debug, verify that the above sentence setcontentoffset no problem, there is a problem, IOS9 on the Yimaidoctorgroupmoretopiccommoncollectioncell awakefromnib method only executed once, and in the other mobile version of the Walk three times, so the original registration of the two types of cell, Here are three seemingly identical cells that are now exactly the same, with the same data. Similar to use the same address, instead of what we think, three kinds of cells have their own independent address, so it is not sliding to look at the specific why still in different system version has this situation, check the information also no clue, have the understanding of the partners also please more guidance!! Finally, only the workaround is attached: three seemingly identical cells are no longer used, so there are modifications to the following reuse identifiers
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{StaticNSString *identifier; if(Indexpath.item <3) {identifier= [NSString stringWithFormat:@"%@-%ld",@"Yimaidoctorgroupmoretopiccommoncollectioncell", Indexpath.item]; Yimaidoctorgroupmoretopiccommoncollectioncell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath]; Cell.type= [NSString stringWithFormat:@"%ld", Indexpath.item +1]; FLOG (@"cell ========%@", cell); returncell; }Else{identifier=@"Yimaidoctorgroupmoretopicmycollectioncell"; Yimaidoctorgroupmoretopicmycollectioncell*cell =[CollectionView dequeuereusablecellwithreuseidentifier:identifier Forindexpath:indexpath]; Cell.type= (int) Indexpath.item +1; returncell; }}
+ (Instancetype) Collectionviewwithobject: (ID)Object{ //Flow LayoutUicollectionviewflowlayout *layout =[[Uicollectionviewflowlayout alloc] init]; Layout.scrolldirection=Uicollectionviewscrolldirectionhorizontal; CGFloat itemheight= Kscreenh-kcollectionviewheight-Knavigtaionheight; Layout.itemsize=Cgsizemake (Kscreenw, itemheight); Layout.minimumlinespacing=0; Layout.minimuminteritemspacing=0; //InitializeYimaidoctorgroupmoretopiccollectionview *collection =[[Yimaidoctorgroupmoretopiccollectionview alloc] Initwithframe:cgrectzero collectionviewlayout:layout]; //Register//Fix iOS9 A custom Uicollectionviewcell only go once awakefromnib for(inti =0; I <3; i++) {[Collection registernib:[uinib nibwithnibname:kcommonidentifier Bundle:nil] Forcellwithreuseidentifier:[nss Tring stringWithFormat:@"%@-%d",@"Yimaidoctorgroupmoretopiccommoncollectioncell", I]]; }//[Collection registernib:[uinib nibwithnibname:kcommonidentifier Bundle:nil] Forcellwithreuseidentifier: Kcommonidentifier];[Collection registernib:[uinib nibwithnibname:kmyidentifier Bundle:nil] Forcellwithreuseidentifier: Kmyidentifier]; //page Outcollection.pagingenabled =YES; //data source, proxyCollection.Delegate=Object; Collection.datasource=Object; //Collection.backgroundcolor =[Uicolor Clearcolor]; returncollection;}
awakefromnib problems of Uicollectionviewcell under IOS9