ios - "Unrecognized selector sent to instance" when using custom table cell -


i have implemented custom table cell , receiveing runtime error ("unrecognized selector sent instance") when table enters cellforrowatindexpath. error occur when trying instantiate custom cell. have achieved before, error won't go away. have prtotype cell , custom class attribute set custom cell uitableviewcell subclass. here custom cell:

#import "favoritecell.h"  @implementation favoritecell @synthesize lblgaugeid, lblmaintitle, bgimage;  - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     bgimage = [uiimage imagenamed:@"tablecellbg.png"];     self = [super initwithstyle:style reuseidentifier:reuseidentifier];     if (self) {         uicolor *transparentbg = [uicolor colorwithred:0.0 green:0.0 blue:0.0 alpha:0.0];         uicolor *foregroundcolor = [uicolor colorwithred:1.0 green:1.0 blue:1.0 alpha:1.0];         //uicolor *shadowcolot = [uicolor colorwithwhite:0.75 alpha:1.0];          cgsize size = self.contentview.frame.size;         self.backgroundview = [[uiimageview alloc] initwithimage:bgimage];         self.lblmaintitle = [[uilabel alloc] initwithframe:cgrectmake(8.0, 0.5, size.width-16, size.height-40)];         [self.lblmaintitle setfont:[uifont systemfontofsize:12.0]];         [self.lblmaintitle settextalignment:nstextalignmentleft];         [self.lblmaintitle setautoresizingmask:(uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight)];         [self.lblmaintitle setbackgroundcolor:transparentbg];          self.lblgaugeid = [[uilabel alloc] initwithframe:cgrectmake(20.0, 31.0, size.width-16, size.height-40)];         [self.lblgaugeid setfont:[uifont boldsystemfontofsize:15.0]];         [self.lblgaugeid settextalignment:nstextalignmentleft];         [self.lblgaugeid settextcolor:foregroundcolor];         [self.lblgaugeid setshadowoffset:cgsizemake(0.2 , 0.2)];         [self.lblgaugeid setautoresizingmask:(uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight)];         [self.lblgaugeid setbackgroundcolor:transparentbg];          [self.contentview addsubview:lblgaugeid];         [self.contentview addsubview:lblmaintitle];     }     return self; }  @end 

and here instatiated (excerpted view controller class):

-(favoritecell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     nsstring *cellidentifier = @"favoritecell";     favoritecell *cell = (favoritecell*)[tableview dequeuereusablecellwithidentifier:cellidentifier]; //error     if(cell == nil){         cell = [[favoritecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];     }     nsstring *sitename = [favekeys objectatindex:indexpath.row];      [cell.lblmaintitle settext:sitename];     [cell.lblgaugeid settext:[allfavorites objectforkey:sitename]];     return cell; } 

here full error message:

* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfconstantstring instantiatewithowner:options:]: unrecognized selector sent instance 0x24bb0'

can offer advice on check? thanks! vivian

using - (void)registernib:(uinib *)nib forcellreuseidentifier:(nsstring *)identifier good idea if had defined custom cell in separate nib file. problem passed nsstring rather uinib object.

do instead:

[self.tblfavorites registernib:[uinib nibwithnibname:@"favoritecellview" bundle:nil] forcellreuseidentifier:@"favoritecell"];

however since used prototype cell rather separate nib, there's no need @ all. instead need make sure prototype cell's reuse identifier set (in case "favoritecell").


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -