2016-08-08 1 views
2

xibファイルをテーブルビューでセルとして使用しようとしています。 registerNibに「オプション値をアンラッピングしている間に予期せずnilが見つかりました」というメッセージが表示されます。私はそれがコンセントを参照することだと思うが、なぜそれが発生するのか分からない。 私の見解は以下の通りです:テーブルビューは、xibセルを使用している間にnilを見つけます。

enter image description here

それが示すように、テーブルビューがプレイ動画・ビュー・コントローラの内部にあります。

私の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が動作していません。これが原因の原因は何ですか?強制的にアンラップすることができ行で

おかげ

+0

xibはインスタンス化されていますか? – penatheboss

+0

@penatheboss私はちょうどviewDidLoadでregisterNibを持っています。私はそれをどのようにインスタンス化すべきですか? –

+1

Xcodeの画面イメージは、UITableViewがViewControllerの 'view'プロパティに接続されていて、' tableView'プロパティには接続されていないことを示しています。 – OOPer

答えて

1

唯一のことは、あなたのtableViewです。参照先コンセントを確認してください。

関連する問題