简体   繁体   English

我可以在UIView子类上设置tag属性吗?

[英]Can I set the tag property on a UIView subclass?

I've got a UIView subclass called CardView, and created an instance like so: 我有一个称为CardView的UIView子类,并创建了一个如下实例:

CardView *newCard = [[CardView alloc] initWithFrame:CGRectMake(x,y,w,h)];

And then I've tried to set the view's tag like this: 然后,我试图像这样设置视图的标签:

newCard.tag = 1;

But that doesn't seem to be actually setting the tag for that view. 但这似乎并没有为该视图设置标签。 If I set a breakpoint around there, and do 如果我在附近设置断点,然后执行

po newCard.tag

in the debugger, it says 在调试器中,它说

error: property 'tag' not found on object of type 'CardView *'

Shouldn't I be getting a tag property as part of the UIView subclass? 我是否应该将标签属性作为UIView子类的一部分?

The debugger console does not understand the Objective C property syntax. 调试器控制台不了解Objective C属性语法。 Instead, do this in the source file: 而是在源文件中执行此操作:

NSLog(@"%d", newCard.tag);

and you'll see it in the console. 然后您将在控制台中看到它。

The debugger understands methods though, although it gets confused about datatypes. 尽管调试器对数据类型感到困惑,但它仍然理解方法。 This debugger command would work: 此调试器命令将起作用:

p (int)[newCard tag]

That's about as objective as GDB gets. 这和GDB一样客观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM