使用故事板中的视图将 XIB 中 UIView 的 UITextField 加载到 ViewCrontroller

Loading UITextField of UIView in XIB to ViewCrontroller with View in storyboard

我不断收到 setValue:forUndefinedKey:]:此 class 与键 dummyTextField 的键值编码不兼容。'

编辑: 我需要将 UIView(nib 文件)中的 UITextField 连接到 ViewController。 UIView 作为 ViewController 中的子视图加载。按下按钮后我想要 UITextField 的内容

请下载以下文件并试用。如果你能帮我解决这个问题,我将不胜感激。

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

请注意,我已成功让按钮在该控制器中工作,错误仅出在文本字段的 IBOutlet 上。

如果您能想出另一种方法来完成此操作(例如使用委托方法),我会洗耳恭听。

谢谢

P.S。我做了 google 它并遇到了很多有稍微类似问题的人,但是它并没有解决我的问题。

为此,您需要先设置根视图控制器。

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.

现在完美运行-:)