search

Home  >  Q&A  >  body text

objective-c - 在实现方法中声明变量与在接口文件中声明实例变量有何不同?

如在m文件中:

@interface KCLoginViewController (){
UITextField *_txtUserName;
UITextField *_txtPassword;
}

与在h文件中:
@property UITextField *_txtUserName;
@property UITextField *_txtPassword;
这两种方式有何差异呢?

迷茫迷茫2766 days ago422

reply all(1)I'll reply

  • 阿神

    阿神2017-04-24 09:13:44

    The standard syntax is @property UITextField *txtUserName; without underlining, this method will automatically generate a getter setter method, so it can be accessed with self.txtUserName, and a member variable of _txtUserName will be created,

    And @interface KCLoginViewController (){
    UITextField *_txtUserName; UITextField *_txtPassword;
    }
    The getter setter method will not be generated, so you can only access it with _txtUserName _txtPassword

    reply
    0
  • Cancelreply