我正在構建一個應用程序,讓用戶創建一個包含標題和文本的「故事」。表格單元格不顯示分配給屬性的字符串是否太長
我正在實現一個顯示所有創建的故事的tableView。到目前爲止,一切正常但這裏是我的問題:
當用戶輸入一個標題或文本的長度是什麼tableViewCell將能夠顯示,該單元根本不顯示。 儘管如此,其他人名字較短。
我正在使用單元格樣式「副標題」。
如何限制顯示在單元格中的文本數量以及導致此錯誤的原因?因爲即使我找到了修復方法,但屏幕上的文字仍然可能會出現問題。
這裏是我的UITableViewController
類代碼:
class StoryTableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return savedStories.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
cell.textLabel?.text = savedStories[indexPath.row].title
cell.detailTextLabel?.text = savedStories[indexPath.row].text
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
這裏是UI的從界面生成器的截圖:
因此,如果用戶輸入1000個字的故事,你想顯示在那個特定的細胞每一個字? –
**理想情況下,只有前x個字符。** 但我的tableView目前不顯示任何內容,當文本太長。 – Marmelador
添加UI的屏幕截圖。 –