Note that there are some explanatory texts on larger screens.

plurals
  1. POInitializing controls on NIB load - EXC_BAD_ACCESS on destruction
    primarykey
    data
    text
    <p>I'm loading an overlay view from an xib in my storyboard / iOS6 / ARC app. This view has an image view, text view and some switches. My problem is that after customizing some of the controls, I get EXC_BAD_ACCESS when trying to transition away from the view back to my main view. </p> <p>I'm loading the view by creating an instance from my view controller (during a <code>button_touchup</code> function) and calling UIView <code>transitionWithView</code>. I can initialize the <code>imageView</code> and <code>text</code> with data passed from the VC through an instance function that populates those controls. This works fine and I can transition away no problem.</p> <p>The problem comes in when I try to customize the switch colors - e.g. <code>_toggleSwitch.thumbTintColor = [UIColor colorwithRed.....];</code> The toggle shows up white and then crashes with bad_exec during interaction or on destruction of the view (when transitioning back to the main view / <code>self removeFromSuperview</code>). I've tried doing this before I transition to the view with an instance function, I've tried doing it on <code>-awakeFromNib</code> and <code>-didMoveToWindow</code> without luck. I've tried saving the colors in strong properties on the class. The only thing that works is using a built in constant - e.g. <code>_toggleSwitch.thumbTintColor = [UIColor redColor]</code>. </p> <p>How can I customize the appearance of these switches without crashing? I even tried passing in the custom UIColor object from my presenting view controller through the overlay view's setup function the same way I'm passing in the text to <code>textfield.text</code> and the image to <code>imageview.image</code> - by assigning it to <code>self.toggleswitch.thumbTintColor</code> and it <em>still</em> causes a bad exec. How do I customize the switches in my xib?</p> <p>EDIT:Ok, I didn't think the code was all that revelatory, but here's the overlay</p> <pre><code>overlay.h @property (strong, nonatomic) IBOutlet UISwitch *switchFB; </code></pre> <p>This works fine in -awakeFromNib / anywhere else in the xib</p> <pre><code>Overlay.m _switchFB.thumbTintColor = [UIColor redColor]; </code></pre> <p>This causes exc_bad_access</p> <pre><code>_switchFB.thumbTintColor = [UIColor colorWithRed:225.0f green:152.0f blue:140.0f alpha:1.0f]; </code></pre> <p>The exception is thrown when I'm trying to transition back to the superview (or sometimes when interacting with the modified toggle):</p> <pre><code>- (IBAction)buttonCancelClick:(id)sender { [UIView transitionWithView:self.superview duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{ [self removeFromSuperview]; } completion:nil ]; } </code></pre> <p>I figured it has to do with memory access to the created UIColor object. I don't have a problem accessing objects I pass into the Overlay to initialize the text an image views, so I modifed the setup function (called from the parentVC) that initializes those objects to initialize my switch as well. This still crashes.</p> <pre><code>Overlay.h @property (strong, nonatomic) IBOutlet UITextView *textField; @property (strong, nonatomic) IBOutlet UIImageView *imageView; Overlay.m - (void)setup:(UIImage *)img text:(NSString *)txt color:(UIColor *)col { self.switchFB.thumbTintColor = col; self.textField.text = txt; self.imageView.image = img; } ParentVC.m OverlayPublish *olay = [[NSBundle mainBundle] loadNibNamed:@"OverlayPublish"owner:self options:nil][0]; [olay setup:[UIImage imageNamed:@"test.png"] text:@"test txt" color:[UIColor colorWithRed:225.0f green:152.0f blue:140.0f alpha:1.0f]]; [UIView transitionWithView:self.view.superview.superview duration:0.5 options:UIViewAnimationOptionTransitionCurlDown animations:^{ [self.view.superview.superview addSubview:olay]; } completion:nil </code></pre> <p>Edit2: stack trace - I went back to removeFromSuperView.</p> <blockquote> <ul> <li><p>thread #1: tid = 0x1c03, 0x01d8209b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=1, address=0x51019e21)</p> <p>frame #0: 0x01d8209b libobjc.A.dylib`objc_msgSend + 15</p> <p>frame #1: 0x0224d41c CoreFoundation`CFRelease + 108</p> <p>frame #2: 0x02272e54 CoreFoundation`-[__NSArrayM dealloc] + 196</p> <p>frame #3: 0x01d849ff libobjc.A.dylib`-[NSObject release] + 47</p> <p>frame #4: 0x01d73927 libobjc.A.dylib<code>ReleaseValue std::for_each&lt;__gnu_cxx::__normal_iterator&lt;objc_references_support::ObjcAssociation*, std::vector&lt;objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator&lt;objc_references_support::ObjcAssociation&gt; &gt; ,ReleaseValue&gt;(__gnu_cxx::__normal_iterator&lt;objc_references_support::ObjcAssociation*, std::vector&lt;objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator&lt;objc_references_support::ObjcAssociation&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;objc_references_support::ObjcAssociation*, std::vector&lt;objc_references_support::ObjcAssociation, objc_references_support::ObjcAllocator&lt;objc_references_support::ObjcAssociation&gt; &gt; &gt;, ReleaseValue) + 72 frame #5: 0x01d73632 libobjc.A.dylib</code>_object_remove_assocations + 296</p> <p>frame #6: 0x01d7a7aa libobjc.A.dylib`objc_destructInstance + 60</p> <p>frame #7: 0x01d7a7cf libobjc.A.dylib`object_dispose + 20</p> <p>frame #8: 0x00b2601a UIKit`-[UIImage dealloc] + 217</p> <p>frame #9: 0x01d849ff libobjc.A.dylib`-[NSObject release] + 47</p> <p>frame #10: 0x00c0df90 UIKit`-[UIImageView dealloc] + 752</p> <p>frame #11: 0x00b4199c UIKit`-[UIView release] + 93</p> <p>frame #12: 0x00b497fb UIKit`-[UIView(Hierarchy) removeFromSuperview] + 190</p> <p>frame #13: 0x00b43ee5 UIKit`-[UIView dealloc] + 375</p> <p>frame #14: 0x00d06a01 UIKit`-[_UISwitchInternalView dealloc] + 288</p> <p>frame #15: 0x00b4199c UIKit`-[UIView release] + 93</p> <p>frame #16: 0x00b497fb UIKit`-[UIView(Hierarchy) removeFromSuperview] + 190</p></li> </ul> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload