2011-06-18 2 views
0

は、次のコードを持っている:どのように、不特定の識別子を宣言するのですか?

#import "UsingViewsViewController.h" 

@implementation UsingViewsViewController 
@synthesize pageControl; 
@synthesize imageView1, imageView2; 

- (void)dealloc 
{ 
    [pageControl release]; 
    [imageView1 release]; 
    [imageView2 release]; 
    [super dealloc]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 


// Implement viewDidLoad to do additional setup after loading the view, typically from a  nib. 
- (void)viewDidLoad 
{ 
    // --- initialize the first imageview to display an image--- 
    [imageView1 setImage:[UIImage imageNamed:@"iMac_old.jpeg"]]; 
    tempImageView = imageView2; 

    //--- make the first imageview visible and hide the second--- 
    [imageView1 setHidden:NO]; 
    [imageView2 setHidden:YES]; 

    //--- Add the event handler for the page controller --- 
    [pageControl addTarget:self 
        action:@selector(pageTurning:) 
      forControlEvents:UIControlEventValueChanged]; 
    /* 
    UIActionSheet *action = 
    [[UIActionSheet alloc] 
    initWithTitle:@"Title of action sheet" 
    delegate:self 
    cancelButtonTitle:@"OK" 
    destructiveButtonTitle:@"Delete message" 
    otherButtonTitles:@"Option 1",@"Option 2", nil]; 
    [action showInView:self.view]; 
    [action release]; 
    */ 

    /* 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Hello" 
          message:@"This is an alert view" 
          delegate:self 
          cancelButtonTitle:@"OK" 
          otherButtonTitles:@"Option 1", @"Option 2", nil]; 
          [alert show]; 
          [alert release];*/ 
          [super viewDidLoad]; 

} 

//--- When the page controls value is changed--- 
- (void)pageTurning: (UIPageControl *)pageController { 
    //--- get the page number you can turning to --- 
    NSInteger nextPage = [pageController currentPage]; 
    switch (nextPage) { 
     case 0: 
      [tempImageView setImage: 
      [UIImage imageNamed:@"iMac_old.jpeg"]]; 
      break; 
     case 1: 
      [tempImageView setImage: 
      [UIImage imageNamed:@"iMac.jpeg"]]; 
      break; 
     case 2: 
      [tempImageView setImage: 
      [UIImage imageNamed:@"Mac8100.jpeg"]]; 
      break; 
     case 3: 
      [tempImageView setImage: 
      [UIImage imageNamed:@"MacPlus.jpeg"]]; 
      break; 
     case 4: 
      [tempImageView setImage: 
      [UIImage imageNamed:@"MacSE.jpeg"]]; 
      break; 
     default: 
      break; 
    } 

    //--- Switch the two imageviews--- 
    if (tempImageView.tag==0) { 
     //--- imageView1--- 
     tempImageView = imageView2; 
     bgImageView = imageView1; 
    } 
    else { 
     //---imageView2--- 
     tempImageView = imageView1; 
     bgImageView = imageView2; 
    } 

    //---animate the two views flipping--- 
    [UIView beginAnimations:@"flipping view" 
    context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationTransition:tempImageView]; 
    cache:YES]; 

    [tempImageView setHidden:YES]; 

    [UIView commitAnimations]; 

    [UIView beginAnimations:@"flipping view" 
        context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationTransition:tempImageView]; 
cache:YES]; 

    [bgImageView setHidden:NO]; 

    [UIView commitAnimations]; 

} 



/* 
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    NSLog(@"%d", buttonIndex); 
} 
*/ 

/* 
-(void)actionSheet:(UIActionSheet *)actionSheet  clickedButtonAtIndex:(NSInteger)buttonIndex { 
    NSLog(@"%d", buttonIndex); 
} 
*/ 


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

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

@end 

私の問題は、XcodeのはtempImageViewが指定されていない識別子であり、コンパイルされませんことを私に言っていることです。

変数として宣言する必要がありますか?もしそうなら、どこでそれを宣言すればよいのですか?ヘッダーファイルでも宣言する必要がありますか?

ありがとうございます。

+0

あなたのコードでは、より多くの書式設定を使用することができます。 4つのスペースで指定するか、フォーマットボタンを押します。 –

+0

すべての行は最初に4つのスペースが必要ですか、それとも最初の行ですか?私は最初の行だけでやった。 – pdenlinger

+0

私はあなたがすべての行をインデントすると思われると思う。 –

答えて

0

その変数を宣言する必要があります。 @synthesize imageView1, imageView2; 変更それ::この行 (あなたinterfase中)

UIImageView *tempImageView; 

、あなたの.mファイル編集中:あなたの.hファイルの追加で @synthesize imageView1, imageView2, tempImageView ;

はそれが役に立てば幸い!


UPDATE

メモリ関連のものを忘れていた...あなたの- (void)deallocに追加します。

[imageView2 release]; 
[tempImageView release]; //ADD THIS LINE 
[super dealloc]; 

UPDATE

をと同じ操作を行いますあなたの.mファイルの編集中に、その後(ごinterfase中)

UIImageView *bgImageView; 

このライン:あなたの.hファイルの追加で

@synthesize imageView1, imageView2, tempImageView; 変更それに:@synthesize imageView1, imageView2, tempImageView, bgImageView;

あなた- (void)deallocに追加:

[imageView2 release]; 
[tempImageView release]; 
[bgImageView release]; //ADD THIS LINE 
[super dealloc]; 
+0

ありがとう。変更を加え、それは良いようです。 – pdenlinger

+0

しかし、 'bgImageView'は宣言されていない識別子として表示されます。私が 'UIImageView'を意味するかどうかを質問します。これに対処する方法は? – pdenlinger

+0

申し訳ありませんが、あなたはbgImageViewについてあなたが言ったことを見ました。ありがとうございました。 – pdenlinger

関連する問題