• 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: newbie interface problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie interface problem


  • Subject: Re: newbie interface problem
  • From: Bob Sabiston <email@hidden>
  • Date: Wed, 5 Oct 2005 10:42:37 -0500


On Oct 4, 2005, at 7:07 PM, Bob Sabiston wrote:


I am having some trouble with a bunch of interface controls. On my window, I have about 10 different text fields and buttons that I am trying to set from my code. Each field and button I have connected to an outlet in my class. I use something like the following to set them:

- (void)setDuration:(double)d {
    [duration setDoubleValue: d];
    NSLog(@"set Duration to %lf",d);
}

where 'duration' is the outlet name for a text field.


If "duration" is the name of an outlet, the Nib loading machinery will check for a setDuration: method, and call it to set the outlet instead of directly assigning to the "duration" instance variable. But since your setDuration: method takes a double instead of an id, your outlet doesn't get set properly.


As a general rule, any time you have an instance variable (whether it's an outlet or not) with the name "foo", the methods setFoo: and foo should be used only to assign and retrieve that variable's value.

Renaming the above to something like setDurationDoubleValue: should fix the problem. It makes more sense too - the above method isn't changing the "duration" variable to point to another object, it's modifying the object to which it currently points.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Thanks very much for clearing that up. Wow, I had no idea that Cocoa made assumptions about variable names and variable-setting function names.
That is pretty strange, especially with that lower-case followed by upper case. It doesn't make much sense. 'setFoo' sets 'foo' by default? What if there is a variable 'Foo'?


Bob



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: newbie interface problem
      • From: Chris Hanson <email@hidden>
References: 
 >newbie interface problem (From: Bob Sabiston <email@hidden>)
 >Re: newbie interface problem (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Re: No Reference to Table Column
  • Next by Date: Problems with objects getting crossed
  • Previous by thread: Re: newbie interface problem
  • Next by thread: Re: newbie interface problem
  • Index(es):
    • Date
    • Thread