0

If I create project using a View-based application template in Xcode using the iPhone SDK version 4.2 and add just this Objective-C code to the ViewController.m, right after | #pragma mark - View lifecycle | it does not trigger the log message in didAddSubview --

- (void) loadView {
  [super loadView]:
  CGRect frame = CGRectMake(10.0, 10.0, 160, 230);
  UIView *newView = [[[UIView alloc] initWithFrame:frame] autorelease];
  [self.view addSubview:newView];
}

-(void) didAddSubview:(UIView *) subview {
  NSLog(@"subview added %@", subview);
}

Why this doesn't trigger the event handler when run?

Cœur
  • 37,241
  • 25
  • 195
  • 267
littleM
  • 21
  • 3

1 Answers1

4

-didAddSubview: is a method on UIView, not on UIViewController.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • 1
    Yes, thank you! I created a subclass of UIView, NUIView, and moved the -(void) didAddSubview:(UIView *) subview { NSLog(@"subview added %@", subview); } to NUIView.m. Then I changed the class of the UIView in the ViewController.xib from UIView to NUIView. Still, it did not trigger the method. – littleM Mar 07 '11 at 06:34