2
xibファイルをテーブルビューでセルとして使用しようとしています。 registerNibに「オプション値をアンラッピングしている間に予期せずnilが見つかりました」というメッセージが表示されます。私はそれがコンセントを参照することだと思うが、なぜそれが発生するのか分からない。 私の見解は以下の通りです:テーブルビューは、xibセルを使用している間にnilを見つけます。
それが示すように、テーブルビューがプレイ動画・ビュー・コントローラの内部にあります。
私のviewDidLoadは次のとおりです。
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
}
私は他のTableViewControllersで、このペン先が使用されるが、のtableViewが含まれているのUIViewControllerで使用した場合、it'nが動作していません。これが原因の原因は何ですか?強制的にアンラップすることができ行で
おかげ
xibはインスタンス化されていますか? – penatheboss
@penatheboss私はちょうどviewDidLoadでregisterNibを持っています。私はそれをどのようにインスタンス化すべきですか? –
Xcodeの画面イメージは、UITableViewがViewControllerの 'view'プロパティに接続されていて、' tableView'プロパティには接続されていないことを示しています。 – OOPer