Ios tableview在使用xib单元格时发现nil
我正在尝试将xib文件用作表视图中的单元格。但它在registerNib上表示“在展开可选值时意外地发现了nil”。我想这是关于出口的,但我不知道为什么会发生。 我的看法如下: 如图所示,表视图位于播放视频视图控制器内 我的看法是:Ios tableview在使用xib单元格时发现nil,ios,iphone,swift,uitableview,Ios,Iphone,Swift,Uitableview,我正在尝试将xib文件用作表视图中的单元格。但它在registerNib上表示“在展开可选值时意外地发现了nil”。我想这是关于出口的,但我不知道为什么会发生。 我的看法如下: 如图所示,表视图位于播放视频视图控制器内 我的看法是: override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.registerNib(UINib(nibName: "NewestTableViewCell", bundle: nil), forCellReuseIdentifier: "NewestTableViewCell")
}
和表视图方法:
// MARK: - Table view data source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return video.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell : NewestTableViewCell = tableView.dequeueReusableCellWithIdentifier("NewestTableViewCell") as! NewestTableViewCell
let vd = video[indexPath.row]
cell.title.text = vd.title
cell.title.textAlignment = .Right
cell.duration.layer.borderColor = UIColor.whiteColor().CGColor
cell.duration.layer.borderWidth = 1.0
cell.duration.layer.cornerRadius = 3.0
cell.duration.clipsToBounds = true
cell.duration.text = vd.length
imageDl(vd.imageUrl){ image in
cell.videoImage.image = image
}
cell.time.text = vd.published
cell.time.textAlignment = .Right
cell.viewed.text = vd.view
cell.viewed.textAlignment = .Right
return cell
}
我在其他TableViewController中使用了这个nib,但在包含tableView的UIViewController中使用时,它不工作。这是什么原因造成的
谢谢这行中唯一可以强制打开的就是您的tableView。检查其引用出口。是否已实例化xib?@penatheboss我刚刚在viewDidLoad中注册了RNIB。我应该在哪里实例化它以及如何实例化?Xcode屏幕图像显示UITableView连接到ViewController的
视图属性,而不是属性tableView
@OOPer谢谢!我是iOS新手,仍然需要对概念有一些了解