【发布时间】:2011-09-26 18:47:03
【问题描述】:
我对 iPhone 开发还很陌生,所以请原谅我的无知。我用谷歌搜索了一下,到目前为止没有任何用处。这是我想做的:
我希望在触摸 UITextField 时弹出一个子视图(屏幕的其余部分显示在背景中)。弹出窗口是我在 IB 中创建的计算器 UIView。根据 Apple 的开发人员指南,弹出式显示似乎比定制键盘更好。
这是我的问题。如何捕获 UITextField 上的触摸以及如何显示子视图?
我已经尝试过以下方法来显示子视图,但没有成功:
CustomCalculator *customCalc = [[CustomCalculator alloc] initWithNibName:@"CustomCalculator" bundle:nil];
UIViewController *calcController = [self.customCalc.view];
[self.view addSubview:calcController.view];
【问题讨论】:
-
UIViewController *calcController = [self.customCalc.view]; ??为什么要将 UIView 分配给 UIViewController 对象?
-
@Heather: 如果 CustomCalculator 是 UIViewController 的子类,你可以去掉第 3 行,直接使用 [self.view addSubView:customCalc.view];
标签: iphone uitextfield subview addsubview