Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
Hi!

I can't update button's title using outlet. But it don't works((( Does it XCode 3.1 bug?

Here is a code:
PHP:
@interface MyController : NSObject
{
    IBOutlet NSString *myValue;
}
- (void)awakeFromNib;
@end
PHP:
@implementation MyController
- (void)awakeFromNib
{
	myValue = @"Hello World";
}
@end
And screenshot:

Please help me.
Thanks
 
He's trying to bind to the button title to the controller's string.

You need to either make it an @property, or manually define KVC-compliant "myValue"/"setMyValue:" (or whatever) methods and within -awakeFromNib, change the value through the dot syntax or by calling setMyValue: directly. That will trigger the binding and change the button's title.
 
So I see you are using bindings.

So the reason this isn't working for you is your controller object is not KVO compliant for that property.

One way to make this work is to define:

Code:
- (void) setMyValue: (NSString*) aString {...}

and then use that method to set your value.

Even easier is to define myValue as a property and let the compiler synthesize this setter method for you.

So in the interface you add this:

Code:
@property (nonatomic, copy) NSString* myValue;

Then add to the implementation:

Code:
@synthesize myValue;

then in your awakeFromNib:

Code:
self.myValue = @"This Works!";

// or [self setMyValue:@"This Works, too"];

And you should see the button text change.

Hope that helps. The lesson here is that bindings require objects that are Key/Value Observing (KVO) compliant. And KVO compliance needs Key/Value Coding (KVC) compliance to work automatically.

EDIT: Never mind, I see kpua already answered this for you.
 
Or if you were lazy you could just do:
Code:
[self setValue:@"Hello World" forKey:@"myValue"];
But I'm not recommending that ;)
 
Thanks, for replying!!!

One more think: How to set title(e.g. for a button control) if I know only object id (e.g. 26)?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.