简体   繁体   English

使用情节提要中的View将XIB中的UIView的UITextField加载到ViewCrontroller

[英]Loading UITextField of UIView in XIB to ViewCrontroller with View in storyboard

I keep getting a setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dummyTextField.' 我不断收到setValue:forUndefinedKey:]:此类与键dummyTextField的键值编码不兼容。

EDIT: I need to connect the UITextField which is in a UIView (nib file) to the ViewController. 编辑:我需要将UIView(nib文件)中的UITextField连接到ViewController。 The UIView is loaded as a subview within the ViewController. UIView在ViewController中作为子视图加载。 I want the content of UITextField once the button is pressed 按下按钮后,我想要UITextField的内容

Please download the file below and try it out. 请下载下面的文件并尝试一下。 If you can help me with this, it would be much appreciated. 如果您可以帮助我,将不胜感激。

https://drive.google.com/file/d/0B_Z-8IMBX2LcSURBRktzZ2tzWWc/view?usp=sharing https://drive.google.com/file/d/0B_Z-8IMBX2LcSURBRktzZ2tzWWc/view?usp=sharing

Note that I successfully have the button working in that controller, the error is just with the IBOutlet of the textfield. 请注意,我已成功使该按钮在该控制器中工作,该错误仅与文本字段的IBOutlet有关。

If you can figure out another way of accomplishing this (such as using a delegate method), I am all ears. 如果您能找到另一种方法来完成此任务(例如使用委托方法),我会不知所措。

Thank you 谢谢

PS I did google it and came across a lot of people whom have slightly similar issues however it doesn't resolve mine. PS我做了谷歌它,并遇到了很多人有一些类似的问题,但它不能解决我的问题。

For achieve this,you need to set root view controller first. 为此,您需要首先设置根视图控制器。

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
}

After that Click your Project 之后,单击您的项目

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

Now Go subview XIB 现在转到子视图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.

Now it works perfectly-:) 现在,它可以完美运行了-:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM