开发者

How, where to declare unspecified identifier?

Have the following code:

#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];
     */

     /*
    UIA开发者_如何学运维lertView *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

My problem is that Xcode is telling me that tempImageView is an unspecified identifier and won't compile.

Does it need to be declared as a variable? If so, where should I declare it, and what type should it be? Does it need to be declared in the header file too?

Thanks in advance.


you need to declare that variable. In your .h file add: (in your interfase)

UIImageView *tempImageView;

then in your .m file edit this line: @synthesize imageView1, imageView2; change it to: @synthesize imageView1, imageView2, tempImageView ;

Hope it helps!


UPDATE

Forgot memory related stuff.. Add in your - (void)dealloc:

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

UPDATE

Do the same with bgImageView

In your .h file add: (in your interfase)

UIImageView *bgImageView;

then in your .m file edit this line: @synthesize imageView1, imageView2, tempImageView; change it to: @synthesize imageView1, imageView2, tempImageView, bgImageView;

Add in your - (void)dealloc:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜