如何在 .h 文件 iPhone 中声明 index=0
// Declare index in Header.h
index=0;
- (IBAction)next {
index++;
// Set imageCount to as many images as are available
int imageCount=2;
if (index<=imageCount) {
NSString* imageName=[NSString stringWithFormat:@"img%i", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
我在头文件中的哪里声明索引以及如何声明?
// Declare index in Header.h
index=0;
- (IBAction)next {
index++;
// Set imageCount to as many images as are available
int imageCount=2;
if (index<=imageCount) {
NSString* imageName=[NSString stringWithFormat:@"img%i", index];
[picture setImage: [UIImage imageNamed: imageName]];
}
}
Where do I declare index in my header file and how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
index
仅在-next
方法中使用,则可以定义静态变量。请注意,所有实例将共享相同的
索引
。但我认为最好将
index
作为 ivar,例如在构造实例时自动初始化为 0,并且除
next
之外的方法都可以使用索引
。此外,每个实例都有自己的索引
。If
index
is used only within the-next
method, you can define a static variable.Note that all instances will share the same
index
.But I believe it's better to make
index
as an ivar, e.g.it is automatically initialized to 0 when the instance is constructed, and methods other than
next
can use theindex
. Also, each instance will have its ownindex
.