didAddSubview 在 ViewController 中不起作用

发布于 2024-10-20 17:23:18 字数 525 浏览 8 评论 0原文

如果我使用 iPhone SDK 版本 4.2 在 Xcode 中使用基于视图的应用程序模板创建项目,并将此 Objective-C 代码添加到 ViewController.m 中,紧随 | 之后。 #pragma mark - 查看生命周期 |它不会触发 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);
}

为什么运行时不会触发事件处理程序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琴流音 2024-10-27 17:23:18

-didAddSubview:UIView 上的方法,而不是 UIViewController 上的方法。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文