osx - app crashes when button clicked -
i ios dev background. creating simple mac app in appdelegate adding nsviewcontroller instance window , have button in nsviewcontroller class. when click button crashes. looked @ these posts not figure out whats wrong in app. why app not able "attach" action?
here code in app delegate
prviewcontroller *pcvc = [[prviewcontroller alloc] initwithnibname:@"prviewcontroller" bundle:nil]; [self.window.contentview addsubview:pcvc.view];
function button
-(ibaction)startclicked:(id)sender{nslog@"btn selected";}
when click on button, app crashes. following stack trace:
producer_consumer[45914:303] -[__nscftype startclicked:]: unrecognized selector sent instance 0x101d07680 producer_consumer[45914:303] -[__nscftype startclicked:]: unrecognized selector sent instance 0x101d07680 producer_consumer[45914:303] ( 0 corefoundation 0x00007fff900deb06 __exceptionpreprocess + 198 1 libobjc.a.dylib 0x00007fff8ce803f0 objc_exception_throw + 43 2 corefoundation 0x00007fff9017540a -[nsobject(nsobject) doesnotrecognizeselector:] + 186 3 corefoundation 0x00007fff900cd02e ___forwarding___ + 414 4 corefoundation 0x00007fff900cce18 _cf_forwarding_prep_0 + 232 5 appkit 0x00007fff85862959 -[nsapplication sendaction:to:from:] + 342 6 appkit 0x00007fff858627b7 -[nscontrol sendaction:to:] + 85 7 appkit 0x00007fff858626eb -[nscell _sendactionfrom:] + 138 8 appkit 0x00007fff85860bd3 -[nscell trackmouse:inrect:ofview:untilmouseup:] + 1855 9 appkit 0x00007fff85860421 -[nsbuttoncell trackmouse:inrect:ofview:untilmouseup:] + 504 10 appkit 0x00007fff8585fb9c -[nscontrol mousedown:] + 820 11 appkit 0x00007fff8585750e -[nswindow sendevent:] + 6853 12 appkit 0x00007fff85853644 -[nsapplication sendevent:] + 5761 13 appkit 0x00007fff8576921a -[nsapplication run] + 636 14 appkit 0x00007fff8570dbd6 nsapplicationmain + 869 15 producer_consumer 0x0000000100001c02 main + 34 16 libdyld.dylib 0x00007fff920127e1 start + 0
)
any appreciate thanks
i think view controller being released prematurely because not holding reference it:
prviewcontroller *pcvc = [[prviewcontroller alloc] initwithnibname:@"prviewcontroller" bundle:nil]; [self.window.contentview addsubview:pcvc.view];
you need make pcvc
instance variable of class using view or better still shake ios background , stop using view controllers altogether in favour of loading view straight nib.
this article gave me idea being memory management related.
Comments
Post a Comment