我需要跟踪一些 ImageView ,这些 ImageView 可以在屏幕上拖动并位于其他 ImageView 中。例如足球进球。我想通过为足球附加一些额外的属性、当前进球和进球中看到的时间来做到这一点。
@property (nonatomic, retain) IBOutlet IBOutletCollection(UIImageView)
NSArray *multipleFootballs;
我想,我必须创建一个 super 类。 虽然我不确定最好的方法是什么?
EDIT3:谢谢尼克,但是我如何访问实例属性?
@interface FootballImageView : UIImageView {
int intCurrentGoal;
}
@property (readwrite) int intCurrentGoal;
@implementation FootballImageView
@synthesize intCurrentGoal;
-(id)init {
self = [super init];
if(self) {
// do your initialization here...
}
return self;
}
@end
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (id football in multipleFootballs) {
//if ([[touches anyObject] intCurrentGoal] == 0) {
//if (football.intCurrentGoal == 0) {
最佳答案
应该很容易:
- 创建一个继承自 UIImageView 的新子类,我们称之为 MyImageView
- 将所需的自定义实例变量添加到 header
- 在界面构建器(“身份”选项卡)中选择新的 MyImageView 作为旧 UIImageView 的类
- 将
IBOutletCollection(UIImageView)
更改为IBOutletCollection(MyImageView)
-
- (id)init
{
self = [super init];
if(self) {
// do your initialization here...
}
return self;
}
回复编辑3
您面临的问题是您在touchesBegan中使用的匿名类型(id)。放入这样的支票:
for (FootballImageView *football in multipleFootballs) {
if(football.intCurrentGoal == 0) {
football.intCurrentGoal++;
}
}
关于objective-c - Objective C、iOS,如何将几个 int 变量附加到属于 IBOutletCollection 一部分的 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6045166/