5

このエラーに関する無数の投稿を調べてきました。

Undefined symbols for architecture i386:
  "_OBJC_IVAR_$_UIViewController._view", referenced from:
      -[ViewController viewDidLoad] in ViewController.o

ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

私はすでに.mファイルをチェックし、ライブラリをリンクしてバンドルファイルをコピーしました。私は xcode 4.6.2 バージョンを使用しています。ViewDidLoadでプログラム的にボタンを作りたいです。

4

3 に答える 3

12

正確な理由は不明ですが、このエラーには多くの理由が考えられます。

  1. ボタンがインスタンス化されていない (割り当てられて初期化されていない)、つまりボタンが nil です。

  2. ボタンをグローバルに作成した場合は、selfを使用してアクセスします

元:

myButton = [[UIButton alloc] init];// Don't use like this
self.myButton = [[UIButton alloc] init];// Use like this

編集: コードをこれに置き換えます

self.button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.button.frame = CGRectMake(10, 220, 150, 30);
[self.button setTitle:@"Show" forState:UIControlStateNormal];
[self.button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[_view addSubview:self.button]; // Note if you have set property of _view then use it as self.view because it also may be the cause of error.

お役に立てば幸いです。

于 2013-04-30T10:15:46.140 に答える
0

を使用していますか?

_viewYour.doSomething

いいえ

_view.doSomething

私は今この間違いを犯しました。

于 2014-07-08T03:16:32.550 に答える