-3

以前、stackoverflow で質問しましたが、それは機能しsetNeedsDisplayません。私は怠け者ではなく、あらゆることを試しましたが、それでもうまくいきません。たぶん、どこに問題があるのか​​ わかりません。誰でも問題を見つけるのを手伝ってもらえますか?

//viewcontroller.m
#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController
@synthesize frequency;
- (void)viewDidLoad
{
    hi = [[cro alloc]init];
    [self.view addSubview:hi];
    CGFloat fu = frequency.value;
    [hi changefreq:fu];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)change:(id)sender
{
    CGFloat fu = frequency.value;
    [hi changefreq:fu];
}
@end
//cro.m
#import "cro.h"

@implementation cro
@synthesize fffff;
CGFloat freee;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
-(void)drawRect:(CGRect)rect
{

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 1);
    CGContextSetLineJoin(context, kCGLineJoinRound);
    NSLog(@"hi i am here %f",fffff);
    const CGFloat amplitude = 200/2;
    for(CGFloat x = 0; x < 600; x += 0.5)
    {
        CGFloat y = amplitude * cosf(2 * M_PI * (x / 600) * freee) + 200;
        if(x == 0)
            CGContextMoveToPoint(context, x, y);
        else
            CGContextAddLineToPoint(context, x, y);
    }
    CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
    self.clearsContextBeforeDrawing = NO;
    CGContextStrokePath(context);
}
-(void)changefreq:(CGFloat)fre
{
    NSLog(@"fre= %f",fre);
    freee = fre;
    [self setNeedsDisplay];
}

@end

ここにプロジェクトがあり ます http://www.sendspace.com/file/lzt4b0

4

3 に答える 3