【发布时间】:2018-06-10 17:20:54
【问题描述】:
如何增加特定部分的特定单元格(在 UITableView 中)的高度(在我的情况下,第二部分是带有 Swift 的图像)。 我不知道是否可以将我的单元格设置为自动调整大小,但我目前想要的只是增加该单元格的大小,因为我看不到里面的任何东西。 我的应用看起来像这样:
我想增加里面有 WebView 的那个单元格的大小。
这是我的代码:
extension DetailsViewController: UITableViewDelegate, UITableViewDataSource{
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section {
case 0: return 6
case 1: return 1
default:
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section{
// Section 1: Repository Details
case 0:
let cell = detailsTableView.dequeueReusableCell(withIdentifier: "repoDetailsCell", for: indexPath) as! DetailsTableViewCell
// Set each row from first section
switch indexPath.row{
case 0:
cell.avatarImageView.downloadedFrom(link: "\(selectedRepo.owner.avatarURL)")
if indexPath.row == 0{
self.detailsTableView.rowHeight = 60
}
cell.textLabel?.isHidden = true
cell.detailTextLabel?.text = selectedRepo.description
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.numberOfLines = 0
return cell
case 1:
cell.textLabel?.text = selectedRepo.description
cell.textLabel?.numberOfLines = 0
cell.detailTextLabel?.isHidden = true
return cell
case 2:
cell.textLabel?.text = "Open Issues"
cell.detailTextLabel?.text = String(selectedRepo.openIssuesCount)
return cell
case 3:
cell.textLabel?.text = "Forks"
cell.detailTextLabel?.text = String(selectedRepo.forksCount)
return cell
case 4:
cell.textLabel?.text = "Watchers"
cell.detailTextLabel?.text = String(selectedRepo.watchersCount)
return cell
case 5:
cell.textLabel?.text = "URL"
cell.detailTextLabel?.text = selectedRepo.htmlURL
cell.detailTextLabel?.textColor = UIColor.blue
cell.detailTextLabel?.numberOfLines = 0
return cell
default:
return cell
}
// Section 2: Webview
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "repoWebviewCell", for: indexPath) as! DetailsTableViewCell
// Set the WebView from Section 2
switch indexPath.row{
case 0:
UIWebView.loadRequest(cell.webView)(NSURLRequest(url: NSURL(string: "\(selectedRepo.htmlURL)/blob/master/README.md")! as URL) as URLRequest)
return cell
default:
return cell
}
default: return UITableViewCell()
}
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 200
}
}
【问题讨论】:
标签: ios swift uitableview uiviewcontroller