0

So I've got an NSViewController (MyVC) set up like so:

//MyVC.h
...
@property (nonatomic, retain) IBOutlet NSTextField *input;
...

//MyVC.m
...
@synthesize input;

- (id)init
{
    self = [super initWithNibName: @"MyVC" bundle: [NSBundle mainBundle]];
    NSLog(@"%@", input); //prints (null) always
    return self;
}

- (void)loadView
{
    [super loadView];
    NSLog(@"%@", input); //still (null)
}
...

//MyVC.xib

Custom View       [Referencing Outlet:    File's Owner.view]
    Text Field    [Referencing Outlet:    File's Owner.input]

Now, when I load this NSViewController (by way of MyVC *vc = [[MyVC alloc] init];) and load it into a window, I see the Text Field appropriately. However, as the above paste (and several BAD_ACCESSes) would suggest, vc.input is never properly pointing to the Text Field.

Notes:

  • This project is running ARC.
  • This is not a simplification or generalization. I've run this exact code to no avail.
  • All IBOutlets are definitely set up appropriately.
Patrick Perini
  • 22,555
  • 12
  • 59
  • 88
  • Do you try no NSLog in `viewDidLoad`? In `init` it will be always be NULL. In `loadView` I don't remember. – Nekto Sep 06 '11 at 16:51
  • 2
    NSViewController (note, not UIViewController) does not have -viewDidLoad. (http://stackoverflow.com/questions/4492485/when-programming-for-mac-os-x-is-there-an-equivalent-to-viewdidload) – Patrick Perini Sep 06 '11 at 16:54
  • 1
    Where’s the actual `IBOutlet` declaration? –  Sep 06 '11 at 17:03
  • Could the property and ivar be different, and the IBOutlet is setting the wrong one? What happens if you log `self.input` in `loadView`? – Daniel Dickison Sep 06 '11 at 17:30

1 Answers1

1

The error was a combination of things.

One of my revisions was missing the IBOutlet tag, and none of them were retaining references to the ViewController at runtime.

Patrick Perini
  • 22,555
  • 12
  • 59
  • 88