加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – @synthesize不再自动添加到.m文件中?

发布时间:2020-12-14 17:16:09 所属栏目:百科 来源:网络整理
导读:使用连接器连接按钮,文本字段和标签后,不会自动为标签和文本字段(两个都是出口)生成@synthesize语句,因此当我尝试访问标签或文本字段或其属性时. m文件它说“使用未声明的标识符”,但 Xcode不应该自动完成吗?我正在按照本教程 http://www.youtube.com/watch
使用连接器连接按钮,文本字段和标签后,不会自动为标签和文本字段(两个都是出口)生成@synthesize语句,因此当我尝试访问标签或文本字段或其属性时. m文件它说“使用未声明的标识符”,但 Xcode不应该自动完成吗?我正在按照本教程 http://www.youtube.com/watch?v=c3Yd2kCPs5c(大约4:35它显示自动生成的@synthesize语句不再出现在xcode中),这就是我猜测导致此错误.我不应该手动添加这些吗?解决这个问题的最佳方法是什么?

-------.m Fie--------
//
//  ViewController.m
//  AutoConnection
//
//  Created by Administrator on 29/03/13.
//  Copyright (c) 2013 Administrator. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view,typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)changeLabel:(id)sender {

    NSString *message = [[NSString alloc] initWithFormat:@"Hello %@",[myTextFeild text]];
    [myLabel setText:message];

}
@end

---------.h file------------
//
//  ViewController.h
//  AutoConnection
//
//  Created by Administrator on 29/03/13.
//  Copyright (c) 2013 Administrator. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
- (IBAction)changeLabel:(id)sender;

@property (weak,nonatomic) IBOutlet UILabel *myLabel;

@property (weak,nonatomic) IBOutlet UITextField *myTextFeild;

@end

解决方法

看到你的代码后,

@property (weak,nonatomic) IBOutlet UILabel *myLabel;
@property (weak,nonatomic) IBOutlet UITextField *myTextFeild;

你将它们作为:

[myLabel setText:message];

这是不正确的.

它应该是[_myLabel setText:message];

或[self.myLabel setText:message];

原因:使用XCode4.4及更高版本运行的编译器将您的属性自动合成为

@synthesize yourProperty=_yourProperty;

或者,如果您希望使用相同的属性名称,则可以覆盖它

@synthesize yourProperty;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读