2016-07-08 7 views
1

私はSwiftとAutolayoutに自分自身を訓練するためのアプリのようなYouTubeを構築しています。iOS再利用テーブルセルデザイン

しかし、私はビデオのテーブルを表示する必要がある複数の場所で問題に直面しています。次に、他のテーブルで再利用する1つのビデオのセルを設計することですどうやってするか。

コンテナビューをセルに配置しようとしましたが、「コンテナビューは実行時に繰り返される要素に配置できません」というエラーが表示されます。

PS:私は既に、ビデオのTableViewControllerを参照しているContainerViewを考えましたが、問題は、私のdifferentsテーブルに持っている唯一のセルではないということです。 (時には、底にコメントがあり、時には他のものもあります。まもなく、テーブルにはさまざまなタイプのセルがあります)。

答えて

1

別のxibファイルを使用して再利用可能な表のセルを作成します。つまり、CustomTableViewCell.swiftとCustomTableViewCell.xibを作成します。カスタムセルを使用するには、UITableViewDataSourceに登録する必要があります。

This stackoverflow answer may be of use

import UIKit 
class TableViewController: UITableViewController { 
    let items = ["Item 1", "Item2", "Item3", "Item4"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     tableView.registerNib(UINib(nibName: "CustomOneCell", bundle: nil), forCellReuseIdentifier: "CustomCellOne") 
    } 

// MARK: - UITableViewDataSource 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return items.count 
    } 
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("CustomCellOne", forIndexPath: indexPath) as! CustomOneCell 
     cell.middleLabel.text = items[indexPath.row] 
     cell.leftLabel.text = items[indexPath.row] 
     cell.rightLabel.text = items[indexPath.row] 
     return cell 
    } 
} 
+0

ありがとうございました!私は働く;) – NathanVss