Search code examples
iphoneiosobjective-cxcodexcode4

Undefined symbols for architecture i386: "_OBJC_IVAR_$_UIViewController._view", referenced from:


I've been looking through countless posts about this error:

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)

I already checked .m file and link libraries and copy bundle file. i am using xcode 4.6.2 version. i want to make programmatically Button in ViewDidLoad.


Solution

  • There is uncertainty for the exact reason but there may be many reasons for this error:

    1. Either the button isn't instantiated (allocated & initialized) i.e. button is nil.

    2. If you have made button globally then access it using self

    Ex:

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

    EDIT : replace your code with 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.
    

    Hope it helps you.