ios - Nib IBOutlet 导致应用程序崩溃

标签 ios swift swift3 nib iboutlet

真的需要你的帮助!我已经浏览了所有可能解决此问题的帖子,但似乎没有任何效果。

所以我使用 .xib 文件在 ProfileFoldingCellView.swift 中创建 subview ,在我尝试在同一类中添加 IBOutlet 之前,它工作得很好。这是代码:

import Foundation
import UIKit

class ProfileFoldingCellView: UIView {

    @IBOutlet var mainLabel: UILabel!
    public var cellIndex: Int = 0

    init(index: Int) {
        super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))

        cellIndex = index
        print("Index: \(cellIndex)")

        setupContentView()
    }

    func setupContentView() {
        let contentView = UINib(nibName: "ProfileFoldingCellView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
        contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        addSubview(contentView)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupContentView()
    }

}

如您所见,标签 IBOutlet 的创建没有任何问题,并且没有其他过时或未使用的导出漫游。

Label Outlet http://imgur.com/a/jb9CA

我还确保将 ProfileFoldingCellView.swift 设置为文件所有者的类。

在我连接 socket 之前,一切都运行良好!然后我得到这个错误:

Error http://imgur.com/a/6hHPG

相信我,我什么都试过了。我可能已经重新创建了 socket 一百万次,但没有任何效果。任何帮助将不胜感激!

最佳答案

将您的文件所有者保留为 NSObject 并将您的 View 类设置为 ProfileFoldingCellView,您的 mainLabel 应该连接到 UIView 对象而不是文件所有者 enter image description here

关于ios - Nib IBOutlet 导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43816253/

相关文章:

swift3 - 如何在imageview swift 3中设置图像?

ios - URLSessionTask 是如何运行的

ios - MKPinAnnotationView 不显示标题

iphone - 在 iOS 应用程序中跟踪用户指标?

ios - 在 Alamofire 中使用 get 请求时,如何快速修复无效的 JSON 响应?

ios - 标签上不能换行

ios - 在 Collection View 中使用自定义流布局时添加标题

swift - 我是否需要明确说明我想在 xcode 9、swift 4 中使用 cocoapods 安装哪个版本的 alamofire

ios - 一个 UITableView Swift 中的 2 个自定义 UITableViewCell

带有输入消息和发布数据的 JSON Post