Ano*_*957 3 xcode objective-c ios
使用连接器连接按钮,文本字段和标签后,不会自动为标签和文本字段(两个都是出口)生成@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
Run Code Online (Sandbox Code Playgroud)
看到你的代码后,
@property (weak, nonatomic) IBOutlet UILabel *myLabel;
@property (weak, nonatomic) IBOutlet UITextField *myTextFeild;
Run Code Online (Sandbox Code Playgroud)
你将它们作为:
[myLabel setText:message];
Run Code Online (Sandbox Code Playgroud)
这是不正确的.
它应该是 [_myLabel setText:message];
要么 [self.myLabel setText:message];
原因:使用XCode4.4及更高版本运行的编译器将您的属性自动合成为
@synthesize yourProperty=_yourProperty;
Run Code Online (Sandbox Code Playgroud)
或者,如果您希望使用相同的属性名称,则可以覆盖它
@synthesize yourProperty;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3059 次 |
| 最近记录: |