Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why is this object being prematurely deallocated under ARC?
  2. //  TestViewController.m
  3. @implementation TestViewController
  4.  
  5. @synthesize scrollContentView
  6.  
  7. - (void)viewDidLoad
  8. {
  9.     [super viewDidLoad];
  10.  SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
  11.  
  12. [self.scrollContentView addSubview:secondViewController.view];
  13. }
  14.  
  15. @end
  16.  
  17. // SecondViewController.m
  18. - (void)viewDidLoad
  19. {
  20.     [super viewDidLoad];
  21.     UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  22.     [button1 addTarget:self action:@selector(button1Click:) forControlEvents:UIControlEventTouchUpInside];
  23.     button1.frame = CGRectMake(20, 45, 280, 40);
  24.     [self.view addSubview:button1];
  25. }
  26.  
  27. - (IBAction)button1Click:(id)sender
  28. {
  29.     NSLog(@"test");
  30. }
  31.        
  32. @implementation TestViewController{
  33.     SecondViewController *secondViewController; // with ARC ivars are strong by default
  34. }
  35.        
  36. secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
  37.        
  38. - (void)addChildViewController:(UIViewController *)childController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);