1

I have a basic project that contains nothing but an NSForm. All i'm trying to do is add some rows to it. From my understanding, I should be able to do this somehow like the following:

- (void) awakeFromNib
{
    NSLog(@"Test: %p", form);
    [form addEntry: @"Hello World 1"];
    [form addEntry: @"Hello World 2"];
    [form addEntry: @"Hello World 3"];

    [form sizeToCells];
}

I have confirmed that my form is not null (the test print shows its address), but my form still contains nothing but the two default entries that are displayed when I drag an NSForm onto my view.

enter image description here

Where am I going wrong?

Kyle
  • 17,317
  • 32
  • 140
  • 246
  • No, the outlet is set. If not, then the NSLog(@"Test: %@", form) would have output nil. Thanks though! – Kyle May 29 '12 at 16:29

1 Answers1

2

I've just spent a while playing about with this, and it seems the problem is doing it in awakeFromNib:.

In a sample project, I made an outlet for the NSForm in my app delegate class. Then I pasted your code into applicationDidFinishLaunching:. It worked (albeit with a graphical glitch in the cell that was selected by default).

If your really need the logic to go in awakeFromNib:, could you maybe put it in its own method and call it using performSelector:afterDelay:?

Amy Worrall
  • 16,250
  • 3
  • 42
  • 65
  • Hmm, weird. I got this to work as you mentioned (both the `applicationDidFinishLaunching` and the `performSelector:afterDelay:` worked, but then once I resized the window they all went back to just showing 'Field 1' and 'Field 2'. I think i'm going to submit a bug report to apple. – Kyle May 29 '12 at 16:33
  • I'd actually never heard of `NSForm` before — I had to look it up in the docs to make sure you hadn't got a class name wrong! I'm not sure how much love Apple are putting in to it these days. Regarding the resizing, though, I think you're seeing an interaction with the new Auto-Layout feature. If you set your nib not to use it (first tab on the right hand side of the inspector, turn off "Use auto layout"), it seems to work for me. Do file a bug anyway though :) – Amy Worrall May 29 '12 at 16:40
  • Bug report submitted! I'll update it with the `Use auto layout` information as well, as that fixed the resizing issue for me. I still had the display glitch though. Hopefully they can shed some light on it for me! – Kyle May 29 '12 at 16:44