开发者

Accessing IB object/controll from a class method

开发者 https://www.devze.com 2023-04-02 23:43 出处:网络
Are the objects/controls that you created using IB accessible from a class method? @Nekto: @interface CopyController : UIViewController

Are the objects/controls that you created using IB accessible from a class method?

@Nekto:

@interface CopyController : UIViewController
{
    UIActivityIndicatorView *myActivity;
}

@prope开发者_C百科rty (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];
}


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 to File's Owner by selecting ib_object_name in drop down menu.

Full explanation can be found, for example, here : Creating and Connecting an Outlet


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消