Note that there are some explanatory texts on larger screens.

plurals
  1. POA few IBOutlets pointing to nil
    primarykey
    data
    text
    <p>After a long while I've finally started working with Objective-C again, on my only complete app so far. The goal is to eventually refactor for ARC and possibly storyboards, but for the time being I'm polishing the iOS 4.x target. I am quite rusty, so bar with me if this is a stupid question.</p> <p>I have a button in my main view that triggers the showAction method. The method is as follows: </p> <pre class="lang-objc prettyprint-override"><code>- (void)showAbout { AboutViewController *aboutView = [[[AboutViewController alloc] init] autorelease]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { aboutView.modalPresentationStyle = UIModalPresentationFormSheet; } else { aboutView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; } [self presentModalViewController:aboutView animated:YES]; } </code></pre> <p>The AboutViewController class has this .h:</p> <pre class="lang-objc prettyprint-override"><code>@interface AboutViewController : UIViewController &lt;UIActionSheetDelegate, MFMailComposeViewControllerDelegate&gt; { } - (IBAction)dismiss:(UIButton *)sender; - (IBAction)feedback:(UIButton *)sender; @property (retain) IBOutlet UIButton *dismissButton; @property (retain) IBOutlet UIButton *feedbackButton; @property (retain) IBOutlet UIImageView *background; @property (retain) IBOutlet UITextView *textView; @end </code></pre> <p>and everything has been connected properly in the .xib file (the same one for iPhone and iPad). The actions are triggered as expected, and the outlets are accessible, but only on iPhone. When running on iPad, only textView is properly initialized, and all the rest points to nil. </p> <p>In the .m I have tried this:</p> <pre class="lang-objc prettyprint-override"><code>@implementation AboutViewController @synthesize dismissButton = _dismissButton; @synthesize feedbackButton = _feedbackButton; @synthesize background = _background; @synthesize textView = _textView; // ... - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"obj self.dismiss: %@", self.dismissButton); NSLog(@"frame dismiss: %@", NSStringFromCGRect(self.dismissButton.frame)); } </code></pre> <p>On iPhone I get this:</p> <pre class="lang-objc prettyprint-override"><code>2012-02-08 22:51:00.341 myapp[17290:207] obj self.dismiss: &lt;UIButton: 0x70281d0; frame = (180 410; 120 30); opaque = NO; autoresize = LM+W+RM+TM; layer = &lt;CALayer: 0x7028260&gt;&gt; 2012-02-08 22:51:00.342 myapp[17290:207] frame dismiss: {{180, 410}, {120, 30}} </code></pre> <p>On iPad, instead, I get this:</p> <pre class="lang-objc prettyprint-override"><code>2012-02-08 22:51:40.428 myapp[17320:207] obj self.dismiss: (null) 2012-02-08 22:51:40.428 myapp[17320:207] frame dismiss: {{0, 0}, {0, 0}} </code></pre> <p>There is nothing else that happens depending on the UI Idiom, and I'm really confused about this. It's as if on the iPad the outlets for anything other than textView are not set, even though they are correctly linked up in the .xib file. In viewWillAppear, self.textView <strong>is</strong> working as expected also on iPad. I also tried doing this in viewDidLoad, which should be called before viewWillAppear if I'm not mistaken, and even in the dismiss: method, but they are just never available.</p> <p>The reason I need to access the buttons' frames is that the about view is relatively complex and fails to reposition its subviews automatically. The only thing I need to do is make the buttons wider on the larger modal view on iPad.</p> <p>Any hints would be greatly appreciated!</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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