• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: setStringValue problems with dynamically loaded views.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setStringValue problems with dynamically loaded views.


  • Subject: Re: setStringValue problems with dynamically loaded views.
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 17 Mar 2010 14:42:58 -0700

On Wed, Mar 17, 2010 at 2:16 PM, Kevin Brock <email@hidden> wrote:
> - (id)initWithText:(NSString*)field_contents
> {
>        NSBundle* mybundle = [NSBundle bundleWithPath:@"/Library/Frameworks/MyFramework.framework"];

You shouldn't hardcode bundle paths like this. You could use
+[NSBundle bundleWithIdentifier:] (preferred) or +[NSBundle
bundleForClass:] instead.

>        self = [self initWithNibName:@"MyEditText" bundle:mybundle];
>        if(self)
>        {
>                [textField setStringValue:field_contents];

-initWithNibName:bundle: doesn't actually load the nib, so at this
point textField hasn't been hooked up to anything yet. If you set a
breakpoint on this line you'll find that textField == nil. You will
need to move this logic elsewhere.

The documentation for NSViewController (perhaps the release notes?)
makes oblique reference to NSWindowController's -windowDidLoad method,
which is designed for just this kind of scenario. NSViewController
doesn't have an analog for -windowDidLoad; instead you are expected to
override -loadView, call super's implementation, and then perform your
setup. That is the approach I would recommend.

You could theoretically do it in -awakeFromNib, but that won't work if
your view controller exists as an object in another nib, since it will
get -awakeFromNib twice.

Hope that helps,
--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: setStringValue problems with dynamically loaded views.
      • From: Kevin Brock <email@hidden>
References: 
 >setStringValue problems with dynamically loaded views. (From: Kevin Brock <email@hidden>)

  • Prev by Date: re: CoreData database sharing and migration
  • Next by Date: Re: CoreData database sharing and migration
  • Previous by thread: setStringValue problems with dynamically loaded views.
  • Next by thread: Re: setStringValue problems with dynamically loaded views.
  • Index(es):
    • Date
    • Thread