Objective c 如何,在何处声明未指定的标识符?
具有以下代码:Objective c 如何,在何处声明未指定的标识符?,objective-c,cocoa-touch,ios4,Objective C,Cocoa Touch,Ios4,具有以下代码: #import "UsingViewsViewController.h" @implementation UsingViewsViewController @synthesize pageControl; @synthesize imageView1, imageView2; - (void)dealloc { [pageControl release]; [imageView1 release]; [imageView2 release];
#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是一个未指定的标识符,无法编译
它是否需要声明为变量?如果是,我应该在哪里声明它,它应该是什么类型?它也需要在头文件中声明吗
提前感谢。您需要声明该变量。 在.h文件中添加: (在你的干涉案中) 然后在.m文件中编辑这一行:
@synthesis-imageView1,imageView2代码>
将其更改为:@synthesis-imageView1、imageView2、tempImageView代码>
希望有帮助
更新
忘记了与记忆有关的东西。。添加您的-(void)dealloc
:
[imageView2 release];
[tempImageView release]; //ADD THIS LINE
[super dealloc];
[imageView2 release];
[tempImageView release];
[bgImageView release]; //ADD THIS LINE
[super dealloc];
更新
对bgImageView
在.h文件中添加:
(在你的干涉案中)
然后在.m文件中编辑这一行:@synthesis-imageView1、imageView2、tempImageView代码>
将其更改为:@synthesis-imageView1、imageView2、tempImageView、bgImageView代码>
添加您的-(void)dealloc
:
[imageView2 release];
[tempImageView release]; //ADD THIS LINE
[super dealloc];
[imageView2 release];
[tempImageView release];
[bgImageView release]; //ADD THIS LINE
[super dealloc];
您的代码可以使用更多的格式-只需确保CAN的每一行都缩进四个空格,或者点击“格式”按钮。每一行的开头需要有四个空格,还是只是第一行?我只是在第一行做的。我想你应该把每一行缩进。谢谢。进行了更改,看起来很好。但是,“bgImageView”显示为未声明的标识符。询问我的意思是“UIImageView”。怎么处理?抱歉,刚才看到你说的bgImageView。谢谢。我更新了答案,请务必声明您使用的每个变量,无论它们是某些方法的局部变量还是整个类的全局变量(如本例)。这应该是变量的范围