views:

440

answers:

1

Hi

Can anyone help me in that I am only trying to change the Title on an UIBarButtonItem from a different class.

My code is:

- (IBAction) spanishPush {  
    SafetyTalks *bbiTitle = [[SafetyTalks alloc] init];
    bbiTitle.bbiOpenPopOver.title = @"Spanish";
}

SafetyTalks = the class I am trying to reference bbiOpenPopOver = the UIBarButtonItem.

I can change the Title when in the SafetyTalks class by simple:

bbiOpenPopOver.title = @"Talk Topics";

but cannot do it when I am out of that class.

Please help.

Andy

A: 

What you can do is to define a property in the SafetyTalks class. Declare it and provide custom getter and setter. This way, the title can be get and set outside the class.

In the header file, add:

@interface SafetyTalks : ... {
     // ....
}

// ....

@property (assign) NSString *title;

// ....

@end

In the source file, add:

@implementation SafetyTalks

// ....

- (NSString *)title {
    return self.bbiOpenPopOver.title;
}

- (void)setTitle:(NSString *) value {
   self.bbiOpenPopOver.title = value;
}

// ....

@end
Laurent Etiemble
I cannot get past the header file as it says warning: property 'title' 'copy' attribute does not match super class 'UIViewController' propertyCheersAndy
Andy McCartney
Sorted:-(void)didTitle:(NSString *)string; in the header file - thanks Laurent as you did point me to the correct method.
Andy McCartney
You are welcome. As you didn't specify the superclass, I went with the "title" property; but you got the idea.
Laurent Etiemble