Как, где объявить неуказанный идентификатор? - PullRequest
0 голосов
/ 18 июня 2011

Имеется следующий код:

#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 - это неопределенный идентификатор и не будет компилироваться.

Должно ли оно быть объявлено как переменная?Если так, где я должен объявить это, и какой тип должен быть?Обязательно ли это указывать в заголовочном файле?

Заранее спасибо.

1 Ответ

0 голосов
/ 19 июня 2011

вам нужно объявить эту переменную. В вашем .h файле добавьте: (в вашем интерфейсе)

UIImageView *tempImageView;

затем в вашем .m файле отредактируйте эту строку: @synthesize imageView1, imageView2; измените его на: @synthesize imageView1, imageView2, tempImageView ;

Надеюсь, это поможет!


UPDATE

Забыл вещи, связанные с памятью .. Добавьте в свой - (void)dealloc:

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

UPDATE

Сделайте то же самое с bgImageView

В вашем .h файле добавьте: (в вашем интерфейсе)

UIImageView *bgImageView;

затем в вашем .m файле отредактируйте эту строку: @synthesize imageView1, imageView2, tempImageView; измените его на: @synthesize imageView1, imageView2, tempImageView, bgImageView;

Добавьте в свой - (void)dealloc:

[imageView2 release];
[tempImageView release];
[bgImageView release]; //ADD THIS LINE
[super dealloc];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...