0
iOS上でUITableViewを使用してリストを作成しようとしていますが、カスタムセルを使用すると常に空であり、空のセルと設定した数は表示されません。カスタムUITableViewCellを使用しているときにiOS UITableViewが空です
ViewController.swift
import UIKit
class ViewController: UITableViewController {
var collections = ["Collection 1", "Collection 2", "Collection 3", "Collection 4", "Collection 5", "Collection 6"]
var descriptions = ["Collection description 1", "Collection description 2", "Collection description 3", "Collection description 4", "Collection description 5", "Collection description 6"]
let cellIdentifier = "CollTableViewCell"
override func viewDidLoad() {
super.viewDidLoad()
let tableNib = UINib(nibName:"CollectionTableViewCell", bundle:nil)
tableView.registerClass(CollectionTableViewCell.self, forCellReuseIdentifier: cellIdentifier)
tableView.registerNib(tableNib,forCellReuseIdentifier:cellIdentifier)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CollectionTableViewCell
cell.collectionName?.text = collections[indexPath.row]
return cell
}
}
CollectionTableViewCell.swift
import UIKit
class CollectionTableViewCell: UITableViewCell {
@IBOutlet weak var collectionName: UILabel!
@IBOutlet weak var collectionDesc: UILabel!
@IBOutlet weak var collectionImage: UIImageView!
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
}
override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
、それを解決するために私を助けてください。
StoryBoardを使用していますか?もしそうなら、それはどのように見えるのですか? – ZGski
IBOutlets(特にcollectionName)を正しく設定しましたか? – firstinq
クラスとペン先の両方を登録しないで、ペンだけを登録してください。 – deadbeef