私は画像やテキストなどの異なるコンテンツにテーブルを追加しようとしています。 私は2種類のカスタムtableViewCellを作成しました。私はそれがすべて保存されるメイン配列を持っています(イメージはJSONに格納されるためbase64にエンコードされます)。カスタムTableViewCell | Swift
var content = [String]()
var imgCell: ImageTableViewCell = ImageTableViewCell()
var txtCell: TextTableViewCell = TextTableViewCell()
イメージ/テキストを追加する2つのボタンがあります。
@IBAction func textAddButton(sender: AnyObject) {
self.content.append("text")
self.articleTableView.reloadData()
}
テーブルを更新する際に、配列データをカスタムセルに接続して表示する方法を理解しています。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
if content[indexPath.row] == "text" {
return txtCell
}
else {
return imgCell
}
return UITableViewCell()
}
ここにカスタムセルがあります。
class TextTableViewCell: UITableViewCell {
@IBOutlet weak var textArticle: UITextView!
}
を? –
'UITableView'は、(再利用のために)文字列識別子を使用してセルを識別します。あなたが 'UITableView'を使いたいのであれば、そのAPIに従ってそれを使う必要があります。 – shim
大丈夫ですが、問題はどのように配列からデータを接続し、型に応じて、必要なクラスを使用し、それを配列で表示できますか? –