在 UIBarButtonItem setTintColor 上发送的无法识别的选择器

发布于 2024-12-21 11:52:21 字数 1519 浏览 3 评论 0原文

我在应用程序商店中有一个正在使用 Flurry 分析的应用程序。而且我时不时地收到未处理的异常错误,但我无法弄清楚。

NSInvalidArgumentException:-[UIBarButtonItem setTintColor:]:无法识别的选择器发送到实例 0x177b20 消息:应用程序崩溃

我不明白的是,我没有在任何地方设置任何栏按钮项目色调颜色。我有一些自定义视图,我在其中设置右栏按钮项目,但没有色调。

我对按钮的大多数使用都是这样的。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UINavigationBar *bar = [self.navigationController navigationBar];
    [bar setTintColor:[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]];
    self.navigationItem.title = @"Edit User";

    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] 
                                   initWithTitle:@"Save"
                                   style:UIBarButtonItemStylePlain 
                                   target:self
                                   action:@selector(editUser:)];
    self.navigationItem.rightBarButtonItem = saveButton;
    [saveButton release];

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] 
                                     initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                     target:self
                                     action:@selector(cancel)];

    [[self navigationItem] setLeftBarButtonItem:cancelButton];
    [cancelButton release];

}

如果有人对这个问题有任何见解,我将非常感激。我的项目目标是 iOS 4.0 及更高版本。

更新: 我找出了导致 setTintColor 上一些随机问题的原因。我发现我正在实际的栏按钮项目之一上设置色调颜色。我猜测操作系统版本之间存在一些差异,可能会导致崩溃。因此,如果有人能告诉我一种在导航栏中设置自定义右栏按钮项目的操作系统中立的方法,我将不胜感激。

I have an app in the app store that I'm using Flurry analytics on. And I keep getting an unhandled exception error from time to time that I can't figure out.

NSInvalidArgumentException: -[UIBarButtonItem setTintColor:]: unrecognized selector sent to instance 0x177b20
Msg: Application crashed

What I can't figure out is, I'm not setting any bar button items tint color anywhere. I have a few custom views where I am setting the right bar button item, but no tint.

Most of my uses of the button look like this.

- (void)viewDidLoad
{
    [super viewDidLoad];

    UINavigationBar *bar = [self.navigationController navigationBar];
    [bar setTintColor:[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1]];
    self.navigationItem.title = @"Edit User";

    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] 
                                   initWithTitle:@"Save"
                                   style:UIBarButtonItemStylePlain 
                                   target:self
                                   action:@selector(editUser:)];
    self.navigationItem.rightBarButtonItem = saveButton;
    [saveButton release];

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] 
                                     initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                     target:self
                                     action:@selector(cancel)];

    [[self navigationItem] setLeftBarButtonItem:cancelButton];
    [cancelButton release];

}

If anyone has any insight into this issue, I would be very grateful. I am targeting iOS 4.0 and up in my project.

UPDATE:
I figured out what was causing some of the random issues on the setTintColor. I found that I was setting the tint color on one of the actual bar button items. I'm guessing there are some differences between OS versions that can cause crashes. So if anyone can tell me an OS neutral way of setting a custom right bar button item in my navigation bar, it would be appreciated.

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

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

发布评论

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

评论(3

顾北清歌寒 2024-12-28 11:52:21

问题在于 2 个类上错误的 -setTintColor 使用。 -setTintColor 在 4.x 设备上不受支持,因此当旧设备遇到色调颜色时,您将会崩溃。

The problem was with errant -setTintColor usage on 2 classes. -setTintColor is not supported on 4.x devices, so you will crash when older devices bump into the tint color.

童话里做英雄 2024-12-28 11:52:21

你尝试过吗:

self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1];

Have you tried :

self.navigationController.navigationBar.tintColor =[UIColor colorWithRed:0 green:69.0/255 blue:118.0/255 alpha:1];

?

美人骨 2024-12-28 11:52:21

如果您的目标是 iOS 4.0,您可以这样做:
在您的 AppDelegate.m 中,@end 之后最后放置以下代码:

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
    UIColor *color = [UIColor YOUR_COLOR];
    self.tintColor = color;
        //if you want image for background use this code
    UIImage *img  = [UIImage imageNamed: @"IMAGE_NAME.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

@end

希望有所帮助。对我来说这是工作。

if your target is iOS 4.0 you can do this:
In your AppDelegate.m in the end after @end put this code:

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
    UIColor *color = [UIColor YOUR_COLOR];
    self.tintColor = color;
        //if you want image for background use this code
    UIImage *img  = [UIImage imageNamed: @"IMAGE_NAME.png"];
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}

@end

Hope this help. For me it's work.

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