didAddSubview 在 ViewController 中不起作用
如果我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-didAddSubview:
是UIView
上的方法,而不是UIViewController
上的方法。-didAddSubview:
is a method onUIView
, not onUIViewController
.