相當新穎。我試圖將3個自定義單元格填充到TableViewController中。TableViewController中的多個自定義單元格
我已經成功(的幫助),以獲得2毫無問題加載。這是我用於2的代碼:
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row % 2 == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("FirstCell") as! FirstTableViewCell
cell.artImageView.image = UIImage(named: "art")
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier("SecondCell") as! SecondTableViewCell
cell.kidsImageView.image = UIImage(named: "kids")
return cell
}
當我嘗試添加第三行時,這是我遇到麻煩的地方。這是我使用的代碼:
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row % 3 == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("FirstCell") as! FirstTableViewCell
cell.artImageView.image = UIImage(named: "art")
return cell
} else if {
let cell = tableView.dequeueReusableCellWithIdentifier("SecondCell") as! SecondTableViewCell
cell.kidsImageView.image = UIImage(named: "kids")
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier("ThirdCell") as! ThirdTableViewCell
cell.pastaImageView.image = UIImage(named: "pasta")
return cell
}
}
任何幫助將是巨大的。格拉西亞斯。
你沒有,如果else語句在第二個指定條件:'}否則,如果{' –