0

コンパイルして正常に実行されるこの実装ファイルがありますが、ブロック内で未使用の変数の警告が表示されます。ブロックは初めてなので、何が悪いのかよくわかりません。警告がある行にコメントしました。

誰かがこれを説明できますか?前もって感謝します!

#import "RTViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

@interface RTViewController () {
  AVAudioPlayer *backgroundAudioPlayer;
  SystemSoundID burnRubberSoundID;
}

@end

@implementation RTViewController
@synthesize car;
@synthesize testDriveButton;
@synthesize backgroundImage;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Road Trip";

  NSURL* backgroundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                 pathForResource:@"CarRunning" 
                                                 ofType:@"aif"]];
  backgroundAudioPlayer = [[AVAudioPlayer alloc]
                           initWithContentsOfURL:backgroundURL error:nil];
  backgroundAudioPlayer.numberOfLoops = -1;
  [backgroundAudioPlayer prepareToPlay];

  NSURL* burnRubberURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"BurnRubber" ofType:@"aif"]];
  AudioServicesCreateSystemSoundID((__bridge CFURLRef)burnRubberURL, &burnRubberSoundID);

}

- (void)viewDidUnload
{
    [self setCar:nil];
    [self setTestDriveButton:nil];
    [self setBackgroundImage:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  //return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)TestDrive:(id)sender {
  AudioServicesPlaySystemSound(burnRubberSoundID);
  [self performSelector:@selector(playCarSound) withObject:self afterDelay:.2];

  CGPoint center = CGPointMake(car.center.x, self.view.frame.origin.y + car.frame.size.height/2);
  [UIView animateWithDuration:3 animations:^ {
    car.center = center;
  }
                   completion:^(BOOL finished) {
                     [self rotate];
                   }];
}

-(void)playCarSound {
  [backgroundAudioPlayer play];
}

- (void)rotate {
  CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);

  void (^animation) () = ^() {
    car.transform = transform;
  };

  void (^completion) (BOOL) = ^ (BOOL finished) {
    [self returnCar];
  };

  [UIView animateWithDuration:3 animations:animation completion:completion];

}

- (void)returnCar {
  CGPoint center = CGPointMake(car.center.x, self.view.frame.origin.y + self.view.frame.size.height - car.frame.size.height/2);

  void (^animation)() = ^() {
    car.center = center;
  };

  void (^completion)(BOOL) = ^(BOOL finished) {
    [self continueRotation];
  };


  [UIView animateWithDuration:3 animations:animation completion:completion];

}

- (void)continueRotation {
  CGAffineTransform transform = CGAffineTransformMakeRotation(0);

  void (^animation)() = ^() {
    car.transform = transform;
  };

  void (^completion)(BOOL) = ^(BOOL finished) {  //Unused variable 'completion'
    [backgroundAudioPlayer stop];
    [backgroundAudioPlayer prepareToPlay];
  };


  [UIView animateWithDuration:3 animations:animation completion:nil];

}
@end
4

2 に答える 2

0

この警告は、変数をインスタンス化したが、コード内のどこでも使用していないことを意味します。

ただし、これは警告です。コードは引き続きコンパイルされ、正常に動作するはずです。使用されない場合は、何かをインスタンス化する理由がないことを示しているだけです。

于 2012-04-17T18:50:54.053 に答える
0

completion問題は、次の行で変数を使用するのを忘れたことです。

[UIView animateWithDuration:3 animations:animation completion:nil];
                                                              ^^^
                                                              Here

したがって、その行を次のように変更します。

[UIView animateWithDuration:3 animations:animation completion:completion];

また、次のようにコードを記述できることに注意してください。

- (void)continueRotation
{
    [UIView animateWithDuration:3 animations:^{
        car.transform = CGAffineTransformMakeRotation(0);
    } completion:^(BOOL finished) {
        [backgroundAudioPlayer stop];
        [backgroundAudioPlayer prepareToPlay];
    }];
}
于 2012-04-17T18:51:07.770 に答える