从类方法访问 IB 对象/控件
您使用 IB 创建的对象/控件是否可以通过类方法访问?
@Nekto:
@interface CopyController : UIViewController
{
UIActivityIndicatorView *myActivity;
}
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *myActivity;
+(void) activityIndicator:(BOOL)flag;
@end
.m 中的这种实现是不允许的,错误是“在类方法中访问实例变量'myActivety'”。
+(void)activityIndicator:(BOOL)flag
{
if (flag)
[myActivity startAnimating];
else
[myActivity stopAnimating];
}
Are the objects/controls that you created using IB accessible from a class method?
@Nekto:
@interface CopyController : UIViewController
{
UIActivityIndicatorView *myActivity;
}
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *myActivity;
+(void) activityIndicator:(BOOL)flag;
@end
This implementation in the .m will not be allowed, the error was "Instance variable'myActivety' accessed in class method".
+(void)activityIndicator:(BOOL)flag
{
if (flag)
[myActivity startAnimating];
else
[myActivity stopAnimating];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,它们是可以访问的。
您应该添加 @property IBOutlet ib_object_class *ib_object_name;,在 IB 中打开该对象设置,并通过在 drop 中选择
ib_object_name
将引用出口设置为File's Owner
向下菜单。例如,可以在这里找到完整的解释: 创建和连接一个出口
Yes, they are accessible.
You should add
@property IBOutlet ib_object_class *ib_object_name;
, open that object settings in IB and set reference outlet toFile's Owner
by selectingib_object_name
in drop down menu.Full explanation can be found, for example, here : Creating and Connecting an Outlet
您也许可以将出口连接到第一响应者而不是文件的所有者来实现此目的,但我认为您不能从类方法中访问它,因为您的 IBOutlet 属性将是实例级变量。
此处找到了类似的用于将操作链接到多个第一响应者的内容。
You may be able to connect the outlet to the first responder instead of the file's owner to achieve this, but I don't think you can access it from within a class method since your IBOutlet property is going to be an instance-level variable.
Found something similar for linking actions to multiple first responders here.