【发布时间】:2011-05-18 13:06:27
【问题描述】:
我需要跟踪一些可以在屏幕上拖动并位于其他图像视图中的图像视图。例如进球中的足球。我想通过为足球、当前目标和目标中看到的时间附加一些额外的属性来做到这一点。
@property (nonatomic, retain) IBOutlet IBOutletCollection(UIImageView)
NSArray *multipleFootballs;
我想,我必须创建一个超类。 虽然我不确定最好的方法是什么?
EDIT3:谢谢 nick,但我如何访问实例属性?
@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) {
【问题讨论】:
-
你的属性合成了吗? football.intCurrentGoal 只能在您编写了一个 getter 方法或合成一个方法时使用。
[touches anyObject]完全不同:在这种情况下,它将返回一个 UITouch 对象。 -
不要对原始类型使用保留、复制或分配!删除分配。而且您的初始化程序不完整。我会在我的答案中添加一个更简洁的版本......
-
我在回答中添加了编辑 3 的回复。
标签: objective-c ios uiimageview nsarray