如何更改 UIBarButtonItem 标题 - iPhone SDK

发布于 2024-09-01 01:15:57 字数 450 浏览 1 评论 0原文

任何人都可以帮助我,因为我只是尝试更改来自不同类的 UIBarButtonItem 上的标题。

我的代码是:

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

SafetyTalks = 我试图引用的类 bbiOpenPopOver = UIBarButtonItem。

我可以在 SafetyTalks 课程中通过简单的方式更改标题:

bbiOpenPopOver.title = @"Talk Topics";

但在离开该课程时则无法更改标题。

请帮忙。

安迪

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

林空鹿饮溪 2024-09-08 01:15:57

您可以做的是在 SafetyTalks 类中定义一个属性。声明它并提供自定义 getter 和 setter。这样,标题就可以在类外获取和设置。

在头文件中添加:

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

// ....

@property (assign) NSString *title;

// ....

@end

在源文件中添加:

@implementation SafetyTalks

// ....

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

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

// ....

@end

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文