所以我试图在 UITableView 中设置 3 个不同的 tableView 单元格,每个单元格的高度不同。我想知道如何返回 3 个不同的单元格,每个单元格都有自己的自定义高度?
感谢指点或帮助!
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0) {
return 1
}
if(section == 1) {
return 1
}
else {
return 10
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch indexPath.section{
case 0:
let myProfile = tableView.dequeueReusableCellWithIdentifier("ProfileHeaderCell") as! VideoTableViewCell
return myProfile
case 1:
let myInfo = tableView.dequeueReusableCellWithIdentifier("AlbumCell") as! AlbumTableViewCell
return myInfo
default:
let cell = tableView.dequeueReusableCellWithIdentifier("TravelBookCell") as! TravelBookTableViewCell
return cell
}
}
最佳答案
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let section = indexPath.section
if(section == 0) {
return 20
}
if(section == 1) {
return 30
}
else {
return 50
}
}
关于swift - 自定义 tableViewCell 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31643360/