gpt4 book ai didi

objective-c - Objective C、iOS,如何将几个 int 变量附加到属于 IBOutletCollection 一部分的 UIImageView?

转载 作者:行者123 更新时间:2023-11-29 05:04:08 25 4
gpt4 key购买 nike

我需要跟踪一些 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com