ios - addTarget:action:forControlEvents: unrecognized selector sent to instance - uibutton in uitablecell -
* edit: sorry, realised - code working fine, until made table have 3 sections. when single section section headings evrything worked fine when scrolling. have theree sections crashes when scrolling.*
i'm adding button uitablecell. crash occurs when table contents extend beyond table height, , table scrolled extreme bottom.
from error looks if uibutton isn't being created, reports jobscell instead...
also layout in custom uitablecell goes awry. looks jobscell class isn't being initiated cells need reused , displayed on screen?
2014-03-20 15:20:32.080 myapp[52350:60b] mapbtn: <uibutton: 0xa89aff0; frame = (0 0; 59 59); opaque = no; autoresize = rm+bm; tag = 12; layer = <calayer: 0xa89b1a0>> 2 1 2014-03-20 15:20:32.313 myapp[52350:60b] mapbtn: <uibutton: 0xa460620; frame = (0 0; 59 59); opaque = no; autoresize = rm+bm; tag = 12; layer = <calayer: 0xa469b60>> 0 11 2014-03-20 15:20:33.512 myapp[52350:60b] mapbtn: <jobscell: 0xa761ac0; baseclass = uitableviewcell; frame = (0 775; 320 60); autoresize = w; tag = 12; layer = <calayer: 0xa761e20>> 0 12 2014-03-20 15:20:33.512 myapp[52350:60b] -[jobscell addtarget:action:forcontrolevents:]: unrecognized selector sent instance 0xa761ac0 2014-03-20 15:20:33.514 myapp[52350:60b] *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[jobscell addtarget:action:forcontrolevents:]: unrecognized selector sent instance 0xa761ac0' *** first throw call stack: ( 0 corefoundation 0x024461e4 __exceptionpreprocess + 180 1 libobjc.a.dylib 0x020178e5 objc_exception_throw + 44 2 corefoundation 0x024e3243 -[nsobject(nsobject) doesnotrecognizeselector:] + 275 3 corefoundation 0x0243650b ___forwarding___ + 1019 4 corefoundation 0x024360ee _cf_forwarding_prep_0 + 14 5 esc gascert 0x0014a109 -[home_ipvc tableview:cellforrowatindexpath:] + 2873 6 uikit 0x00a5d11f -[uitableview _createpreparedcellforglobalrow:withindexpath:] + 412 7 uikit 0x00a5d1f3 -[uitableview _createpreparedcellforglobalrow:] + 69 8 uikit 0x00a3ede7 -[uitableview _updatevisiblecellsnow:] + 2197 9 uikit 0x00a536a5 -[uitableview layoutsubviews] + 213 10 uikit 0x009d3964 -[uiview(calayerdelegate) layoutsublayersoflayer:] + 355 11 libobjc.a.dylib 0x0202982b -[nsobject performselector:withobject:] + 70 12 quartzcore 0x0429445a -[calayer layoutsublayers] + 148 13 quartzcore 0x04288244 _zn2ca5layer16layout_if_neededepns_11transactione + 380 14 quartzcore 0x042880b0 _zn2ca5layer28layout_and_display_if_neededepns_11transactione + 26 15 quartzcore 0x041ee7fa _zn2ca7context18commit_transactionepns_11transactione + 294 16 quartzcore 0x041efb85 _zn2ca11transaction6commitev + 393 17 quartzcore 0x042bccc6 _zn2ca7display11displaylink14dispatch_itemseyyy + 474 18 quartzcore 0x042bd147 _zn2ca7display16timerdisplaylink8callbackep16__cfrunlooptimerpv + 123 19 corefoundation 0x02404ac6 __cfrunloop_is_calling_out_to_a_timer_callback_function__ + 22 20 corefoundation 0x024044ad __cfrunloopdotimer + 1181 21 corefoundation 0x023ec538 __cfrunlooprun + 1816 22 corefoundation 0x023eb9d3 cfrunlooprunspecific + 467 23 corefoundation 0x023eb7eb cfrunloopruninmode + 123 24 graphicsservices 0x036585ee gseventrunmodal + 192 25 graphicsservices 0x0365842b gseventrun + 104 26 uikit 0x00964f9b uiapplicationmain + 1225 27 esc gascert 0x0001626d main + 141 28 esc gascert 0x00002865 start + 53 ) libc++abi.dylib: terminating uncaught exception of type nsexception
but same code in both classes (except line turning cell clear).
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"jobcell"; uitableviewcell *cell; nsarray *versioncompatibility = [[uidevice currentdevice].systemversion componentsseparatedbystring:@"."]; if ( 6 <= [[versioncompatibility objectatindex:0] intvalue] ) { // ios6 installed cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath]; } else { // ios5 installed cell = [tableview dequeuereusablecellwithidentifier:cellidentifier ]; } // * ios7 table fix [cell setbackgroundcolor:[uicolor clearcolor]]; job *job = 0; int jobsaved = 0; nsstring *jobstring = @""; nsstring *jobpostcode = @""; nsstring *jobdate = @""; // configure cell... if (indexpath.section==0) { job = [self.jobs objectatindex:indexpath.row]; jobsaved = job.jobsaved; jobstring = job.jobaddress; jobpostcode = job.jobpostcode; jobdate = job.jobdate; } else if (indexpath.section==1) { job = [self.jobscommercial objectatindex:indexpath.row]; jobsaved = job.jobsaved; jobstring = job.jobaddress; jobpostcode = job.jobpostcode; jobdate = job.jobdate; } else if (indexpath.section==2) { service *service = [self.jobsservices objectatindex:indexpath.row]; jobsaved = service.jobsaved; jobstring = service.jobaddress; jobpostcode = service.jobpostcode; jobdate = service.jobdate; } uicolor *redcol = [uicolor colorwithred:0.62745098039216 green:0.15294117647059 blue:0.15686274509804 alpha:1.0]; jobstring = [jobstring stringbyappendingstring:@", "]; jobstring = [jobstring stringbyappendingstring:jobpostcode]; //cell.textlabel.text = jobstring; uilabel *joblabel = (uilabel *)[cell viewwithtag:10]; joblabel.text = jobstring; if (jobsaved == 1) { joblabel.textcolor = redcol; } else { joblabel.textcolor = [uicolor blackcolor]; } uilabel *datelabel = (uilabel *)[cell viewwithtag:11]; if (! [jobdate isequaltostring:@""]) { nsdateformatter *formater = [[nsdateformatter alloc] init]; [formater setdateformat:@"yyyy-mm-dd"]; nsdate *date2 = [formater datefromstring:jobdate]; [formater setdateformat:@"d mmm yyyy"]; nsstring *date = [formater stringfromdate:date2]; datelabel.text = date; } else { datelabel.text = @""; } uibutton *mapbtn = (uibutton *)[cell viewwithtag:12]; nslog(@"mapbtn: %@ %d %d",mapbtn, indexpath.section, indexpath.row); [mapbtn addtarget:self action:@selector(showmap:) forcontrolevents:uicontroleventtouchupinside]; cell.tag = indexpath.row; return cell; }
jobscell.h
#import <uikit/uikit.h> @interface jobscell : uitableviewcell @property (nonatomic, strong) iboutlet uilabel *joblabel; @property (nonatomic, strong) iboutlet uilabel *datelabel; @property (nonatomic, strong) iboutlet uibutton *mapbtn; @end
jobscell.m
#import "jobscell.h" @implementation jobscell @synthesize joblabel; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { // initialization code } return self; } - (void)setselected:(bool)selected animated:(bool)animated { [super setselected:selected animated:animated]; // configure view selected state } @end
from log can see tag = 12; has jobscell
object not uibutton
mapbtn: <jobscell: 0xa761ac0; baseclass = uitableviewcell; frame = (0 775; 320 60); autoresize = w; **tag = 12;** layer = <calayer: 0xa761e20>> 0 12
the source of problem in line cell.tag = indexpath.row;
because can 12
Comments
Post a Comment