ios - 使用 Storyboard中的 View 将 XIB 中 UIView 的 UITextField 加载到 ViewCrontroller

标签 ios swift uiview uiviewcontroller uitextfield

我不断收到 setValue:forUndefinedKey:]:此类对于键 dummyTextField 不符合键值编码。'

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

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

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

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

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

谢谢

附言我用谷歌搜索了一下,发现很多人都有类似的问题,但它并没有解决我的问题。

最佳答案

为此,您需要先设置 Root View Controller 。

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

现在去 subview 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.

现在它完美地工作了-:)

关于ios - 使用 Storyboard中的 View 将 XIB 中 UIView 的 UITextField 加载到 ViewCrontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33965973/

相关文章:

ios - WebView 在 Xcode 7.x 中不返回 YouTube 视频 [W/Code+Images]

ios - OpenGL ES屏幕投影矩阵和相机投影矩阵

ios - 如何在 swift 中将字符索引从布局管理器转换为字符串比例

objective-c - drawRect 的 aRect 参数与 UIView 的边界有关

ios - 添加一个 UIView 到另一个

ios - Swift 2 - REST 服务和由搜索栏过滤的 TableView

ios - 解析XML时如何防止将\n附加到NSmutable字符串?

ios - 如何管理每个tableviewCell中的AVAudioPlayer isPlaying?

ios - Swift:创建自定义 View 而不指定框架大小

ios - 自定义 UIView 中的无效上下文 0x0 - 后续问题