iOS : EXC_BAD_ACCESS When pressing a button

-3

I have a tabe view with custom cells wich were created in a different nib, In each cell I have a button. I wan't to deal with the button pressed event in one of my created objects (I call it PlaylistController). In IB I've added this class (PlaylistController) as an Object, then dragged the Touch Up Inside action to the object representation in the IB, and implemented a simple alert when the button is pressed. But when I press the button on the simulator I get EXC_BAD_ACCESS; My stack trace :

Thread 1, Queue : com.apple.main-thread
0   0x010ea09b in objc_msgSend ()
1   0x000202c0 in -[UIApplication sendAction:to:from:forEvent:] ()
6   0x002e41d3 in _UIGestureRecognizerUpdate ()
7   0x01c63afe in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
11  0x01c40e1b in CFRunLoopRunInMode ()
12  0x01bf57e3 in GSEventRunModal ()
13  0x01bf5668 in GSEventRun ()
14  0x0001cffc in UIApplicationMain ()
15  0x0000227d in main at /Users/bysdan/Documents/workspace/Starling/Starling/main.m:16
16  0x000021a5 in start ()

P.S.
I've also tried to do this with an External Object instead of Object but then I get an exception in the line where I try to access the nib.

NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"PlaylistCell" owner:nil options:nil];

How can I do this?

Thanks.

ios
objective-c
asked on Stack Overflow Mar 3, 2013 by RCB • edited Mar 3, 2013 by (unknown user)

1 Answer

2

Just as I feared: Your receiving object has been deallocated straight out from under you, and for one obvious reason: It's not stored strongly. IB takes it on good faith that you have the gumption to retain top-level objects that you reference later in code. When the XIB gets dearchived, and the object you've posted has no owner (outside of the original NSCoder), then it is naturally assumed that it can be deallocated without consequence. Of course, the problem with that is that IB has already bound the object to your button's action. So, when the button calls out to the object, BOOM! Simply add an IBOutlet-prefixed property representing the object, and it should clear itself up.

answered on Stack Overflow Mar 3, 2013 by CodaFi

User contributions licensed under CC BY-SA 3.0