0

私はiOSが初めてです。ここで UITextfield Sematic Issues とそのバリエーションを検索しました。私は非常にシンプルなアプリを作ろうとしています:

テキストフィールドにテキストを入力 Aボタンを押す テキストフィールドに入力されたテキストにラベルを変更します。

しかし、この奇妙なセマティック エラーが発生し続けており、修正方法がわかりません。

コードはここにあります:

.m ファイル。

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *myTextField;


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



- (IBAction)changeLabel:(id)sender;

@end

.h

#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 %@", [myTextField text]];
    [myLabel setText:message];
}

ありがとう。

4

2 に答える 2

0

問題は、「self.」なしでプロパティを直接参照していることです。m ファイルの内容を次のように置き換えます。

@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 %@", [self.myTextField text]];
    [self.myLabel setText:message];
}

@end
于 2013-05-20T06:21:08.133 に答える
0

私はunknown Reciever 'myTextField'それが意味するエラーのようなエラーを期待しています、

IOS 6 Apple では、デフォルトで Synthesize プロパティを提供しているため、使用できます

また

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

また

NSString *message = [[NSString alloc] initWithFormat:@"Hello %@", [self.myTextField text]];
于 2013-05-20T06:25:42.187 に答える