我有一个表格视图,在swift 3中有3个部分 - 其中一个标题标题应包含可更改的数字,该数字会多次更改 这是代码
import UIKit
class ProfileSettingTableViewController: UITableViewController {
var cientAccount = String()
var headerList = ["اعتبار" , "یاری رسانی" , "" ]
override func viewDidLoad() {
super.viewDidLoad()
self.cientAccount.append("تومان ۱۰۰۰")
self.tabBarController?.tabBar.isHidden = true
self.navigationController?.isNavigationBarHidden = true
//////Enable Or Desable Scroll in Devices
let modelName = UIDevice.current.modelName
if modelName == "Simulator" {
tableView.isScrollEnabled = false
}else if modelName == "iPhone 4s" || modelName == "iPhone 4" {
tableView.isScrollEnabled = true
}else if modelName == "iPhone SE" || modelName == "iPhone 5" || modelName == "iPhone 5c" || modelName == "iPhone 5s" || modelName == "iPod Touch 5" || modelName == "iPod Touch 6" {
tableView.isScrollEnabled = true
} else if modelName == "iPhone 6 Plus" || modelName == "iPhone 6s Plus" || modelName == "iPhone 7 Plus" {
tableView.isScrollEnabled = false
} else if modelName == "iPhone 6" || modelName == "iPhone 6s" || modelName == "iPhone 7" {
tableView.isScrollEnabled = false
}
else{
tableView.isScrollEnabled = true
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let returnedView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 25))
returnedView.backgroundColor = UIColor.init(red: 229/255, green: 233/255, blue: 236/255, alpha: 1.0)
let label = UILabel(frame: CGRect(x: -20, y: 7, width: view.frame.size.width, height: 25))
label.text = self.headerList[section]
label.textAlignment = .right
label.textColor = .darkGray
let modelName = UIDevice.current.modelName
if modelName == "iPhone 4s" || modelName == "iPhone 4" {
label.font = UIFont.init(name: "IRANSans", size: 15)
}else if modelName == "iPhone SE" || modelName == "iPhone 5" || modelName == "iPhone 5c" || modelName == "iPhone 5s" || modelName == "iPod Touch 5" || modelName == "iPod Touch 6" {
label.font = UIFont.init(name: "IRANSans", size: 17)
} else if modelName == "iPhone 6 Plus" || modelName == "iPhone 6s Plus" || modelName == "iPhone 7 Plus" {
label.font = UIFont.init(name: "IRANSans", size: 19)
} else if modelName == "Simulator" || modelName == "iPhone 6" || modelName == "iPhone 6s" || modelName == "iPhone 7" {
label.font = UIFont.init(name: "IRANSans", size: 17)
}
else{
label.font = UIFont.init(name: "IRANSans", size: 15)
}
returnedView.addSubview(label)
return returnedView
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow( at: indexPath , animated: true)
if indexPath.section == 0 {
if indexPath.row == 0 {
print("افزایش اعتبار")
performSegue(withIdentifier: "oneSet", sender: self)
} else if indexPath.row == 1 {
print("لیست تراکنش ها")
performSegue(withIdentifier: "twoSet", sender: self)
}
}
else if indexPath.section == 1 {
if indexPath.row == 0 {
print("درباره تیپو")
performSegue(withIdentifier: "threeSet", sender: self)
} else if indexPath.row == 1 {
print("درباره اپلیکیشن")
performSegue(withIdentifier: "fourSet", sender: self)
} else if indexPath.row == 2 {
print("تکرار معرفی")
self.navigationController?.isNavigationBarHidden = true
performSegue(withIdentifier: "introduce", sender: self)
}
} else if indexPath.section == 2 {
if indexPath.row == 0 {
print("تنظیمات پیشرفته")
performSegue(withIdentifier: "masterSetting", sender: self)
}
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40.0
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 37.5
}
}
但是Xcode不允许我使用A(clientAccount)
请帮帮我
答案 0 :(得分:0)
var clientAccount = "harry"
var headerList = [String]()
override func viewDidLoad() {
super.viewDidLoad()
headerList = ["A\(clientAccount)" , "B" , "C" ]
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return headerList[section]
}
func numberOfSections(in tableView: UITableView) -> Int {
return headerList.count
}