我一直得到一个setValue:forUndefinedKey:]:这个类对于关键的dummyTextField不符合键值编码。'
编辑:我需要将UIVextField(它是UIView文件中的UITextField)连接到ViewController。 UIView作为ViewController中的子视图加载。按下按钮后,我想要UITextField的内容
请下载以下文件并试用。如果你可以帮助我,我将不胜感激。
https://drive.google.com/file/d/0B_Z-8IMBX2LcSURBRktzZ2tzWWc/view?usp=sharing
请注意,我成功地在该控制器中使用该按钮,错误只是文本字段的IBOutlet。
如果你能找到另一种方法来实现这一点(例如使用委托方法),我很满意。
谢谢
P.S。我确实谷歌了,并遇到了很多人,他们的问题略有类似,但它并没有解决我的问题。
答案 0 :(得分:1)
为实现此目的,您需要先设置根视图控制器。
var window: UIWindow?
var navController:UINavigationController?
var viewController:ViewController?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
viewController = ViewController(nibName: "subview", bundle: nil);
navController = UINavigationController(rootViewController: viewController!);
navController?.navigationBarHidden = true
window?.rootViewController = navController;
window?.makeKeyAndVisible()
return true
}
之后单击您的项目
You can see now PROJECT and TARGET
Click your project of TARGETS
Click General.
Now you can see the Deployment Info
Delete the Main from Dropbox of Main Interface
现在转到子视图XIB
Click Files's Owner of Placeholder'e.
Then click Identity Inspector of Utility Area which is in right side.
Click Class of CustomClass
Then choose ViewController from Dropdown box of class and click Enter.
And go to Connection's Inspector of Utility Area which is in right side.
Now See the Outlets.Under Outlets, there is View.Now You have drag(Contorl+ drag the Empty Circle to Xib View) the view empty circle to the Xib View.Now empty circle is filled with black or gray color.
Finally connect the textField and Button to Outlet.
现在它完美无缺 - :)