簡體   English   中英

情節提要中IBAction的預期表達

[英]Expected expression for IBAction in storyboard

正在收到“期望的表達式”錯誤,但無法在IBAction方法上找出原因。 已注釋掉錯誤。

你能告訴我怎么了嗎? 謝謝。

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

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

@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);
  [testDriveButton setBackgroundImage:[UIImage animatedImageNamed:@"Button" duration:1.0 ] forState:UIControlStateNormal];

}

- (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) {  
    [backgroundAudioPlayer stop];
    [backgroundAudioPlayer prepareToPlay];
  };


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

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  UITouch *touch = [touches anyObject];
  if(CGRectContainsPoint(car.frame, [touch locationInView:self.view]))
    touchInCar=YES;
  else {
    touchInCar=NO;
    [super touchesBegan:touches withEvent:event];
  }

  UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGesture:)];
  swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
  [self.view addGestureRecognizer:swipeGesture];

  - (IBAction)handleSwipeGesture:(id)sender { // Expected expression

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Content"];
    [[self navigationController]pushViewController:viewController animated:YES];
  }
}
@end

問題是您從未關閉過該方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

有自己的花括號。 一種視覺提示是該方法

- (IBAction)handleSwipeGesture:(id)sender

(您的錯誤所在)開始縮進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM