【发布时间】:2018-04-17 17:19:37
【问题描述】:
附上的图片说明了一切。有什么方法可以防止标题重叠,例如在达到其限制时自动移动到第二行?以编程方式/通过界面生成器。
P.S:我正在从 firebase 数据库中检索名称。这是一个投票页面,标题是展位名称
TableView 控制器
import UIKit
import FirebaseDatabase
var pitchData = [String]()
var myIndex = 0
class PitchTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(false, animated: true)
self.navigationController?.navigationBar.titleTextAttributes = [ NSAttributedStringKey.font: UIFont(name: "Gotham Rounded", size: 19)!]
ref = Database.database().reference() //set the firebase reference
// Retrieve the post and listen for changes
databaseHandle = ref?.child("Afternoon13").queryOrdered(byChild: "BoothPosition").observe(.value, with: { (snapshot) in
pitchData.removeAll()
for child in snapshot.children {
let snap = child as! DataSnapshot
let key = snap.key
pitchData.append(key)
}
self.tableView.reloadData()
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return pitchData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.font = UIFont(name: "Gotham Rounded", size: 20)
cell.detailTextLabel?.font = UIFont(name: "Gotham Rounded", size: 20)
cell.textLabel?.text = pitchData[indexPath.row]
switch (pitchData[indexPath.row]) {
case "ARC - attract, retain and cultivate":
let returnValue: Int = UserDefaults.standard.integer(forKey: "voting")
if (returnValue == 1)
{
cell.detailTextLabel?.text = "Completed ✓"
cell.detailTextLabel?.textColor = UIColor.green
cell.isUserInteractionEnabled = false
}
else {
cell.detailTextLabel?.text = "Vote ᐳ"
cell.detailTextLabel?.textColor = UIColor.blue
}
case "Anytime RCs":
let returnValue: Int = UserDefaults.standard.integer(forKey: "voting1")
if (returnValue == 1)
{
cell.detailTextLabel?.text = "Completed ✓"
cell.detailTextLabel?.textColor = UIColor.green
cell.isUserInteractionEnabled = false
}
else {
cell.detailTextLabel?.text = "Vote ᐳ"
cell.detailTextLabel?.textColor = UIColor.blue
}
【问题讨论】:
-
在tableview中你已经获取了label或者textfield。?
-
您是如何通过情节提要或通过 xib 构建此视图的?
-
哦,对不起,让我添加我的代码
-
cells/tableview 是动态的,所以一切都通过 xib/controller 完成
标签: ios swift xcode uitableview