使用连接器连接按钮、文本字段和标签后,@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