【问题标题】:No Visible @interface for 'MLVPieChartView' declares the selector 'tick' [closed]'MLVPieChartView' 没有可见的@interface 声明选择器'tick' [关闭]
【发布时间】:2013-08-05 01:12:06
【问题描述】:

这个 iOS 东西还是新手,通过教程运行,我有这个 No Visible @interface 错误,我看到了其他线程,但我也找不到答案,我查看了拼写一个 no answer。

**MLVViewController.m**
#import "MLVViewController.h"
#import "MLVPieChartView.h"
#import "MLVPieSlice.h"

@interface MLVViewController ()
{
    MLVPieChartView *pieChartView;
    NSTimer *timer;
}
@end

@implementation MLVViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    pieChartView = [[MLVPieChartView alloc] initWithFrame: self.view.frame];
    [self.view addSubview: pieChartView];


    timer = [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(nextFrame) userInfo:NULL repeats:YES];

}

- (void) nextFrame
{
    [pieChartView tick];
    [pieChartView setNeedsDisplay];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *t = [touches anyObject];
    [pieChartView touchedPoint: [t locationInView: pieChartView]];
}


@end




**MLVPieChartView.m**

#import "MLVPieChartView.h"
#import "MLVPieSlice.h" 

typedef enum
{
    STATE_IDLE,
    STATE_ROTATING,
    STATE_SEPARATING,
    STATE_SEPARATED,
    STATE_JOINING
}   state;


@implementation MLVPieChartView

{
    float xPos, yPos, radius;
    float rotationAngle;
    state animationState;
    BOOL isAnimating;
}

@synthesize pieChart;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        pieChart = [[MLVPieChart alloc] init];
        xPos = 320/2;
        yPos = 330;
        radius = 120;
        rotationAngle = 1;

        [self setState: STATE_IDLE];
    }
    return self;
}

- (void) setState:(state) newState
{
    animationState = newState;
    switch (newState) {
        case STATE_IDLE:
            isAnimating = NO;
            break;
        case STATE_ROTATING:
            isAnimating = YES;
            break;
        case STATE_SEPARATING:
            isAnimating = YES;
            break;
        case STATE_SEPARATED:
            isAnimating = NO;
            break;
        case STATE_JOINING:
            isAnimating = YES;
            break;
    }
}

- (void) tick
{
    switch (animationState)
    {
        case STATE_ROTATING:

            break;
        case STATE_SEPARATING:

            break;
        case STATE_JOINING:

            break;
        default:
            break;
    }
}

- (void) drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawPieChart: context];
}


- (void) drawPieChart:(CGContextRef) context
{
    //clear the screen
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, 320, 480));

    //draw all slices
    float a = rotationAngle;
    for (MLVPieSlice *slice in pieChart.slices) {
        [self drawPieSlice:slice withStartingAngle:a withContext:context];
        a += (slice.pct/100) * (M_PI * 2);
    }
}


- (void) drawPieSlice:(MLVPieSlice *) slice withStartingAngle:(float)startAngle withContext:(CGContextRef) context
{
    float endAngle = startAngle + (slice.pct / 100) * (M_PI * 2);
    float adjY = yPos;
    float rad = radius;

    CGContextSetFillColorWithColor(context, [MLVPieChartView colorFromHexString: slice.color].CGColor);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
    CGContextSetLineWidth(context, 1.0);

    CGContextBeginPath(context);
    CGContextMoveToPoint(context, xPos, adjY);
    CGContextAddArc(context, xPos, adjY, rad, startAngle, endAngle, 0);
    CGContextClosePath(context);

    CGContextDrawPath(context, kCGPathFillStroke);
}

float easeInOutBack(float t, float b, float c, float d) {
    // t: current time, b: begInnIng value, c: change In value, d: duration
    float s = 1.70158;
    if ((t/-d/2) < 1) return c/2*(t*t*(((s*-(1.525))+1)*t -s)) + b;
        return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) +b;
}

float easeOutBounce(float t, float b, float c, float d) {
    if ((t/=d) < (1/2.75)) {
        return c*(7.5625*t*t) + b;
    } else if (t < (2/2.75)) {
        return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
    } else if (t < (2.5/2.75)) {
        return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
    } else {
        return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
    }
}


+ (UIColor *)colorFromHexString:(NSString *)hexString {
    unsigned rgbValue = 0;
    NSScanner *scanner = [NSScanner scannerWithString:hexString];
    [scanner scanHexInt:&rgbValue];
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:((rgbValue & 0xFF)/255.0) alpha:1.0];
}


@end





**MLVPieChartView.h**


#import <UIKit/UIKit.h>
#import "MLVPieChart.h" 

@interface MLVPieChartView : UIView

@property MLVPieChart *pieChart;

+ (UIColor *)colorFromHexString:(NSString *)hexString;

@end

我有 GitHub 上的所有文件https://github.com/thebusiness11/animated-pie-chart

【问题讨论】:

  • “我有一个看起来有点像这样的错误”还不够好。发布 EXACT 错误和您正在使用的行,否则甚至没有人会尝试提供帮助。
  • 标题是准确的错误
  • 好的,这就是足够的信息(感谢编辑),请参阅迈克尔的回答。

标签: ios cocoa-touch cocoa cocos2d-iphone


【解决方案1】:

我正在查看 at your MLVPieChartView.h file,但我没有在其中看到名为“tick”的方法。

您需要将该调用更改为具有“tick”方法的对象。从你的 GitHub 项目中我可以看出,在任何地方都没有声明“tick”方法(在这种情况下你必须创建它)。

【讨论】:

  • 所以该方法需要先在 MLVPieChartView.h 文件中声明,然后才能在 MLVPieChartView.m 文件中设置。那么在MLVViewController.m中调用呢?在 MLVPieChartView.m 文件中,我有一个 - (void) tick
  • 它需要在 .h 文件(“接口”)中声明,并在 .m(“实现”)文件中定义它的代码。
  • 谢谢,缺少代码,- (void) tick; - (void) touchedPoint: (CGPoint) point; - (float) getAngleFromPoint: (CGPoint) point; 遗憾的是,视频在创建后跳过了界面文件。跟随文档的帮助。
  • @thebusiness11 他们跳过它的原因是因为这是常识(也许随着越来越多的人使用 C# 和 Java,他们不再意识到它了)。以后能记住这一点对您来说非常好。
【解决方案2】:

你真正需要做的是回到教程中,找到你第一次遇到问题的地方,找出你不理解的地方并清除它。

然后从教程重新开始,并完全按照说明进行操作。一旦你找到你搞砸的地方,原因应该是清楚的。

老实说,你的问题有点模糊,所以很难给出准确的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多