拥有以下代码:
#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 :(得分:0)
你需要声明那个变量。 在你的.h文件中添加: (在您的interfase中)
UIImageView *tempImageView;
然后在.m文件中编辑此行:@synthesize imageView1, imageView2;
将其更改为:@synthesize imageView1, imageView2, tempImageView ;
希望它有所帮助!
<强>更新强>
忘记与内存相关的内容..添加到- (void)dealloc
:
[imageView2 release];
[tempImageView release]; //ADD THIS LINE
[super dealloc];
<强>更新强>
对bgImageView
在你的.h文件中添加: (在您的interfase中)
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];