0
UITableViewCell에서 하나의 그림과 일부 텍스트를 추가하고 싶습니다. 나는 순수한 코드로있는 UITableViewCell을 구현할 수프로그래밍 방식으로 UITableViewCell에서 UITextView 및 UIImageView 추가 프로그래밍 방식으로 Swift 4
그러나 : 여기에 내가 달성하고자하는 결과이다. 누구든지 UITableViewCell 아래 또는 위에 그림 또는 일부 텍스트를 추가하는 방법을 알고 있습니까? 모든 제안을 부탁드립니다.
import UIKit
class AboutViewController : UITableViewController {
private let about = ["About us"]
private let termsOfService = ["Terms of service"]
private let privacyPolicies = ["Privacy policies"]
private let openSourceLicense = ["Open Source Libraries"]
private let sections = ["about", "termsOfService", "privacyPolicies", "openSourceLicense"]
let myTableView: UITableView = {
let mt = UITableView()
return mt
}()
override func viewDidLoad() {
super.viewDidLoad()
// register cell name
myTableView.register(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
// set DataSource
myTableView.dataSource = self
// set Delegate
myTableView.delegate = self
}
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.rowHeight
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
print("Value: \(about[indexPath.row])")
} else if indexPath.section == 1 {
print("Value: \(termsOfService[indexPath.row])")
} else if indexPath.section == 2 {
print("Value: \(privacyPolicies[indexPath.row])")
} else if indexPath.section == 3 {
print("Value: \(openSourceLicense[indexPath.row])")
}
}
// return the number of cells each section.
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return about.count
} else if section == 1 {
return termsOfService.count
} else if section == 2 {
return privacyPolicies.count
} else if section == 3 {
return openSourceLicense.count
} else {
return 0
}
}
// return cells
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "MyCell")
if indexPath.section == 0 {
cell.accessoryType = .disclosureIndicator
cell.textLabel?.textAlignment = .left
cell.textLabel?.text = "\(about[indexPath.row])"
} else if indexPath.section == 1 {
cell.accessoryType = .disclosureIndicator
cell.textLabel?.textAlignment = .left
cell.textLabel?.text = "\(termsOfService[indexPath.row])"
} else if indexPath.section == 2 {
cell.accessoryType = .disclosureIndicator
cell.textLabel?.textAlignment = .left
cell.textLabel?.text = "\(privacyPolicies[indexPath.row])"
} else if indexPath.section == 3 {
cell.accessoryType = .disclosureIndicator
cell.textLabel?.textAlignment = .left
cell.textLabel?.text = "\(openSourceLicense[indexPath.row])"
}
return cell
}
}
왜 그림과 설명을 추가하지 못하게합니까? 무슨 문제 있니? – rmaddy
더 많은 항목이 있다면 이미지도 스크롤됩니까? 없다면, 가장 간단한 방법은 UIImageView를'self.view'에 추가하는 것입니다.이 곳의 원점은'self.tableView'의 끝 부분입니다. 그렇지 않으면 커스텀'UITableViewCell'을 만드는 것에 관한 문제입니까? 'cellForRowAtIndexPath :'에서 다양한 종류의'UITableViewCell'을 관리하고 있습니까? – Larme
@rmaddy 그림과 설명을 추가하는 방법을 모르겠다. ... – user174782