我不能使用子类中声明的方法

时间:2014-06-23 19:41:35

标签: ios objective-c

我正在尝试使用this project,但我最终遇到了问题。 主要目标是使用StoryBoard为UiNavigationBar设置一些渐变颜色。

1 -

#import "CRGradientNavigationBar.h"

2 -

enter image description here 成为 enter image description here

3 -

    // array of colors
UIColor *firstColor  = [UIColor colorWithRed:255.0f/255.0f green:42.0f/255.0f blue:104.0f/255.0f alpha:1.0f];
UIColor *secondColor = [UIColor colorWithRed:255.0f/255.0f green:90.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
NSArray *colorsArray = [NSArray arrayWithObjects:firstColor, secondColor, nil];

    // setting the navigation bar color
[self.navigationController.navigationBar setBarTintGradientColors:colorsArray];

    // 
NSLog(@"%@", self.navigationController.navigationBar);

错误

No visible @interface for 'UINavigationBar' declares the selector 'setBarTintGradientColors:'

知道在CRGradientNavigationBar.h

中声明了setBarTintGradientColors

NSLog输出

2014-06-23 21:07:04.388 Project[1794:60b] <CRGradientNavigationBar: 0xa5324d0; baseClass = UINavigationBar; frame = (0 20; 320 44); opaque = NO; autoresize = W; gestureRecognizers = <NSArray: 0xa536060>; layer = <CALayer: 0xa5327e0>>

我该如何解决?

1 个答案:

答案 0 :(得分:2)

self.navigationController.navigationBar返回UINavigationBar,而不是CRGradientNavigationBar。你可以施展它:

[(CRGradientNavigationBar *)(self.navigationController.navigationBar) setBarTintGradientColors:colorsArray];