2012-02-21 37 views
0

在我的實現文件中出現了一些讓我無法編譯的錯誤,但是我無法弄清楚它們。在此先感謝您的幫助。實現文件中的錯誤

註釋掉的錯誤信息:

實現文件:

#import "TNRViewController.h" 

@implementation TNRViewController //'@end' is missing in implementation context 

@synthesize myIcon, myBackground, bgImages, shrinkButton; 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
hasMoved = NO; 
    hasShrunk = NO; 
    currentBackground = 0; 

    bgImages = [[NSArray alloc] initWithObjects: 
       [UIImage imageNamed:@"WallPaper_01.png"], 
       [UIImage imageNamed:@"WallPaper_02.png"], 
       [UIImage imageNamed:@"WallPaper_03.png"], 
       [UIImage imageNamed:@"WallPaper_04.png"], 
       [UIImage imageNamed:@"WallPaper_05.png"], 
       nil]; 

    size = CGAffineTransformMakeScale(.25, .25); 
    translate = CGAffineTransformMakeTranslation(0,-100); 

    myBackground.image = [bgImages objectAtIndex:currentBackground]; 
} 

- (void)viewDidUnload 
{ 

    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated 
{ 
    [super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

- (void)dealloc { 
    [myIcon release]; 
    [myBackground release]; 
    [shrinkButton release]; 
    [super dealloc]; 
} 

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [[event allTouches] anyObject]; 
    if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])); // if statement has empty body 
    { 
     if (hasMoved == YES && hasShrunk == YES) { 
      myIcon.transform = CGAffineTransformTranslate(size, 0, 0); 
      hasMoved = NO; 
    } 
     if (hasMoved == YES && hasShrunk == NO) { 
      myIcon.transform = CGAffineTransformMakeTranslation(0, 0); 
      hasMoved = NO; 
    } 
     myIcon.center = [touch locationInView:nil]; 
    } 

} 

- (IBAction)shrink:(id)sender { 
    if (hasShrunk) { 
     [shrinkButton setTitle:@"Shrink" forState:UIControlStateNormal]; 
    } else { 
     [shrinkButton setTitle:@"Grow" forState:UIControlStateNormal]; 
    } 

    if (hasShrunk == NO && hasMoved == NO) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = size; 
     [UIView commitAnimations]; 
     hasShrunk = YES; 
    } 

    else if (hasShrunk == NO && hasMoved == YES) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformScale(translate, .25, .25); 
     [UIView commitAnimations]; 
     hasShrunk = YES; 
    } 

    else if (hasShrunk == YES && hasMoved == YES) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformScale(translate, 1, 1); 
     [UIView commitAnimations]; 
     hasShrunk = NO; 
    } 

    else { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformIdentity; 
     [UIView commitAnimations]; 
     hasShrunk = NO; 
    } 
} 

- (IBAction)move:(id)sender { 
    if (hasMoved == NO && hasShrunk == NO) { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = translate; 
     [UIView commitAnimations]; 
     hasMoved = YES; 
    } 
     else if (hasMoved == NO && hasShrunk == YES){ 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformTranslate(size, 0, -100); 
     [UIView commitAnimations]; 
     hasMoved = YES; 
    } 
     else if (hasMoved == YES && hasShrunk == YES){ 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformTranslate(size, 0, 0); 
     [UIView commitAnimations]; 
     hasMoved = YES; 
    } 
     else 
    { 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:1.0]; 
     myIcon.transform = CGAffineTransformMakeTranslation(0, 0); 
     [UIView commitAnimations]; 
     hasMoved = YES; 
    } 
} 

- (IBAction)change:(id)sender { 
    currentBackground++; 
    if(currentBackground >= [bgImages count]) 
     currentBackground = 0; 

    [UIView beginAnimations:@"changeview" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

    if (currentBackground == 1) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES]; 

    if (currentBackground == 2) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; 

    if (currentBackground == 3) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 

    if (currentBackground == 4) { 
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 

     [UIView commitAnimations]; 
     [myBackground.image = [bgImages objectAtIndex:currentBackground]; //Expected identifier 

} 

頭文件

#import <UIKit/UIKit.h> 

@interface TNRViewController : UIViewController 
{ 

    IBOutlet UIImageView *myIcon; 
    IBOutlet UIImageView *myBackground; 
    IBOutlet UIButton *shrinkButton; 

    NSArray *bgImages; 
    int currentBackground; 
    bool hasMoved; 
    bool hasShrunk; 

    CGAffineTransform translate; 
    CGAffineTransform size; 
} 

@property (retain, nonatomic)IBOutlet UIImageView *myIcon; 
@property (retain, nonatomic)IBOutlet UIImageView *myBackground; 
@property (retain, nonatomic)NSArray *bgImages; 
@property (retain, nonatomic)IBOutlet UIButton *shrinkButton; 

- (IBAction)shrink:(id)sender; 
- (IBAction)move:(id)sender; 
- (IBAction)change:(id)sender; 

@end 
+0

是您的問題1實際上應該是這樣的:我如何修復'@end'在實現上下文中缺少? – sarnold 2012-02-21 01:53:49

+0

是的,我無法弄清楚如何解決這個問題。 – pdenlinger 2012-02-21 06:17:38

回答

1

以下是你在你的源文件註釋中的錯誤。

第一:

@implementation TNRViewController //'@end' is missing in implementation context 

這意味着你在.m文件的末尾缺少@end

二:

[myBackground.image = [bgImages objectAtIndex:currentBackground]; //Expected identifier 

應該是:

myBackground.image = [bgImages objectAtIndex:currentBackground]; 

三:

if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])); // if statement has empty body 

應該

if (CGRectContainsPoint([myIcon frame], [touch locationInView:nil])) // Remove the semi column