2012-02-23 18 views
0

は、このプログラムをコンパイルして実行しようとしましたが、コンソールでこのエラーメッセージを受け取った:スレッド1:信号「SIGABRT」エラーメッセージ

2012-02-23 11:43:53.949 touches_v3[8667:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x6aab1e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key buttonShrink.' 
*** First throw call stack: 
(0x13bc052 0x154dd0a 0x13bbf11 0x9b3032 0x924f7b 0x924eeb 0x93fd60 0x23291a 0x13bde1a 0x1327821 0x23146e 0xd8e2c 0xd93a9 0xd95cb 0x39a73 0x39ce2 0x39ea8 0x40d9a 0x1f3b 0x119d6 0x128a6 0x21743 0x221f8 0x15aa9 0x12a6fa9 0x13901c5 0x12f5022 0x12f390a 0x12f2db4 0x12f2ccb 0x122a7 0x13a9b 0x1c42 0x1bb5) 
terminate called throwing an exception(lldb) 

私がやっている間ので、これは私には意味がありません。ヘッダーファイル内のオブジェクトとして "buttonShrink"をコードし、後でそれを削除し、実装ファイル内のすべての参照を削除しました。ヘッダーファイルまたは実装ファイルにはエラーや警告はありません。

ここでは、これら2つのコードを示します。 ヘッダファイル:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController { 

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

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

    CGAffineTransform translate; 
    CGAffineTransform size; 
    UIButton *move; 

} 

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


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

@end 

実装ファイル:

#import "ViewController.h" 

@interface ViewController() 


@end 

@implementation ViewController 
@synthesize myIcon, myBackground, bgImages, shrinkButton; 

- (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]; 

} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    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(hasMoved == YES && hasShrunk == YES) { 
      myIcon.transform = CGAffineTransformTranslate(size, 0, 0); 
      hasMoved = 0; 
     } 
     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 = YES; 
    } 

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

} 

- (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; 
    } 

    if (hasMoved == NO && hasShrunk == NO) { 
     [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]; 
} 
@end 

答えて

0

「buttonShrink」というアクションにリンクされたInterfaceBuiderのボタンがあります。あなたのクラスのメソッド名を変更したようですが、InterfaceBuilderの関連付けを更新していないようです。

+0

はい、問題が見つかりました。私はぶらぶらしたコンセントを持っていた。一度それを削除すると、それはうまくコンパイルされました。ありがとうございました。 – pdenlinger

1

あなたはおそらく、あなたのnibファイル内buttonShrinkへの参照を持っています。 IBを見てください。どこにいるのかわからない場合は、.xibファイルをgrepすることができます。

+0

「shrinkBut​​ton」と呼ばれるボタンがありますが、表示される「buttonShrink」はありません。 .xibファイルで "buttonShrink"をgrepするにはどうすればよいですか? – pdenlinger

関連する問題