How to access an IBOutlet from another class

前端 未结 3 1637
Happy的楠姐
Happy的楠姐 2020-12-05 15:07

I want to know how to access an @IBOutlet declared in a class from another class

for example, I have a class named myfirstview

class MyFirstView: UIV         


        
3条回答
  •  伪装坚强ぢ
    2020-12-05 15:41

    Its not the recommended way to call a IBOutlet from another class. If u want to call or access a IBOutlet then you should set it as property and then access it.

    For example:

    //ViewControler.h
    
    #import 
    
    @interface ViewController : UIViewController
    
    @property (weak, nonatomic) IBOutlet UILabel *label;
    
    @end
    
    //abc.m
    
    #import 
    #import 
    
    @interface abc
    
    @end
    
    @implementation abc
    
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    ViewController *viewCOntroller= [ViewController alloc] init];
    viewCOntroller.label.text = @"Hello";
    }
    

提交回复
热议问题