我需要跟踪一些可在屏幕周围拖动并位于其他图像视图内的图像视图。例如足球进球。我想通过在足球,当前进球和进球时间中附加一些附加属性来做到这一点。
@property (nonatomic, retain) IBOutlet IBOutletCollection(UIImageView)
NSArray *multipleFootballs;
我认为,我必须创建一个超类。
尽管我不确定执行此操作的最佳方法?
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
将所需的自定义实例变量添加到标题中
在界面构建器(“身份”选项卡)中,选择旧的UIImageViews作为类,将新的MyImageView作为类。
将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++;
}
}