objective c - Unable to Press Buttons in a subView -


I have a subview of the rootViewController and when the call is done, the button can be pressed without error:

  Thread 1: EXC_BAD_ACCESS   

This is important code:

AppDelegate:

  Main View Controller * MainVC = [[Main View Controller alloc] init]; Self.window.rootViewController = mainVC;   

and in the MainViewController class:

  Other ViewController * SomeView = [[OtherViewController alloc] init]; [Self.view addSubview: SomeView.view];   

Loads OtherViewController xib as it executes the viewDidLoad stuff. However, when I try to push one of the buttons on the simulator (on OtherViewController ), I get the error above.

More button code:

  IBOutlet UIImageView * image; // Other ViewController.m in other ViewController.h: (IBAction) button: (ID) Sender {Image.center = CGPointMake (Image.center.x + 1, Image.center.y); }   

There are breakpoints in Other ViewController.h and .m (everywhere with the button). No introduction has occurred in the program Adeliget: error UIApplicationMain (argc, argv, zero, NSStringFromClass ([AppDelegate class]));

Am I not setting up another scene properly so that it is fully functional? How can I get rid of this error from my program?

Your problem is that you create an example once in OtherViewController In your main view controller At the end of the scope, ARC issues the example of your code ViewViewController .

Here's your solution:

in MainViewController.m

  @interface MainViewController () // This is an interface extension, which is your @ implementation Before MainViewController @property (nonatomic, strong) OtherViewContontroller * SomeView; @end   

In your method that creates OtherViewController , replace:

  OtherViewController * SomeView = [[OtherViewController alloc] INS]; [Self.view addSubview: SomeView.view];   

with this:

  self.SomeView = [OtherViewController new]; // & lt; - There is a shortcut for new alloc / init :) [self.view addSubview: self.SomeView.view];    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -