ios - 类没有初始化程序

标签 ios swift uiviewcontroller

我对此真的很陌生,我真的需要帮助。我一直遇到这个问题。 类 DetailViewController 没有初始化器

import UIKit

 class DetailViewController: UIViewController {

@IBOutlet var namelabel : UILabel
@IBOutlet var phoneNumberLabel : UILabel
var contact : Contacts?



override func viewDidLoad() {
    super.viewDidLoad()
    if let contact = self.contact {
        if let name = contact.name {
            self.namelabel.text = name
        }
        if let phoneNumber = contact.phoneNumber {
            self.phoneNumberLabel.text = phoneNumber
        }
    }
    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

最佳答案

这将解决您的问题

@IBOutlet var namelabel : UILabel!
@IBOutlet var phoneNumberLabel : UILabel!

您需要为变量分配一个值(在构造函数中或定义时)或将其标记为可选。

关于ios - 类没有初始化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47194879/

相关文章:

ios - 自定义 CollectionViewCell 在选择时具有默认值

ios - 闭包中的 Inout 参数(Swift)

objective-c - 为什么有时不调用 initWithNibName ?

ios - 构建成功后将文本文件安装/导入到物理设备时 Xcode 崩溃 (RangeException)

ios - 评估项目是否已在数组中

ios - 找不到成员 indexPathForCell

ios - Swift 中的 CocoaLumberjack,如何打印行号和文件名

ios - 在不同的选项卡中弹出 View Controller

iphone - 删除实际的 navigationController 并推送到另一个

ios - 触摸结束声音?