ios - CollectionView [__NSCFConstantString _isResizable]: unrecognized selector sent to instance -
i find signal sigabrt thread when run app. here error message : [__nscfconstantstring _isresizable]: unrecognized selector sent instance 0x5c20
the problem coming [[self mycollectionview]setdatasource:self]; because disappear when comment it.
on i've understand, type of mycollectionview datasource , self not same. why have error.
thanks help
pierre
calviewcontroller.h
#import <uikit/uikit.h> @interface calviewcontroller : uiviewcontroller <uicollectionviewdatasource, uicollectionviewdelegate> @property (weak, nonatomic) iboutlet uicollectionview *mycollectionview; @end
calviewcontroller.m
#import "calviewcontroller.h" #import "customcell.h" @interface calviewcontroller () { nsarray *arrayofimages; nsarray *arrayofdescriptions; } @end @implementation calviewcontroller - (void)viewdidload { [super viewdidload]; [[self mycollectionview]setdatasource:self]; [[self mycollectionview]setdelegate:self]; arrayofimages = [[nsarray alloc]initwithobjects:@"chibre.jpg",nil]; arrayofdescriptions =[[nsarray alloc]initwithobjects:@"test",nil]; } - (nsinteger) collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section { return [arrayofdescriptions count]; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier=@"cell"; customcell *cell = ([collectionview dequeuereusablecellwithreuseidentifier:cellidentifier forindexpath:indexpath]); [[cell myimage]setimage:[arrayofimages objectatindex:indexpath.item]]; [[cell mydescriptionlabel]settext:[arrayofdescriptions objectatindex:indexpath.item]]; return cell; } - (nsinteger)numberofsections:(uicollectionview *) collectionview {return 1; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
your arrayofimages
array of image names (strings), setimage
won't work that. instead of:
[[cell myimage]setimage:[arrayofimages objectatindex:indexpath.item]];
you intended:
[[cell myimage]setimage:[uiimage imagenamed:[arrayofimages objectatindex:indexpath.item]]];
or, equivalently:
cell.myimage.image = [uiimage imagenamed:arrayofimages[indexpath.item]];
you might want rename arrayofimages
arrayofimagenames
(or imagenames
or whatever) eliminate possible source of confusion.
(btw, call not put actual images in array. should create image objects in cellforitematindexpath
on basis of image names in array.)
Comments
Post a Comment