Dan*_*n E 2 tableview ios swift
这是我用于表视图控制器的文件.当我运行项目时,单元格显示以"名称"编写的文本,但不会显示所有文本.
我希望它在同一个单元格中显示整个文本.单元格的大小根据其中的内容而定.
我该如何解决?
import Foundation
import UIKit
class FTBViewController: UITableViewController {
var names = [String]()
var identities = [String]()
override func viewDidLoad() {
names = ["This is the text the cell is displaying but it won't show it all"]
identities = ["A"]
self.navigationItem.title = "Guía"
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("FCell")
cell?.textLabel!.text = names[indexPath.row]
return cell!
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewControllerWithIdentifier(vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
加
cell?.textLabel!.numberOfLines = 0
cell?.textLabel!.lineBreakMode = .ByWordWrapping
cell?.textLabel!.font = UIFont.systemFontOfSize(14.0) // this is optional if you need use this
Run Code Online (Sandbox Code Playgroud)
完整答案
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("FCell")
cell?.textLabel!.numberOfLines = 0
cell?.textLabel!.lineBreakMode = .ByWordWrapping
cell?.textLabel!.font = UIFont.systemFontOfSize(14.0)
cell?.textLabel!.text = names[indexPath.row]
return cell!
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |