我将 UITableView 连接到一个数组。 var shoppingList: [String] = ["鸡蛋", "牛奶","A","B","C","D","E","F","G","H","I ","J","K","L","M","N","O"] 但是,当我在模拟器中运行该应用程序时,它不允许我滚动到末尾。这是为什么?我只能滚动到字母“I”并看到一半的“J”,但无法向下滚动。在 func tableView 中,它显示了正确的数组大小,所以我知道所有项目都在那里,但无法滚动到末尾。下面是屏幕截图。谢谢。 screen shot screen shot 2
这是代码
import UIKit
class TestTableViewController: UITableViewController {
var shoppingList: [String] = ["Eggs", "Milk","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"]
override func viewDidLoad() {
super.viewDidLoad()
print("test")
// 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.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
print(shoppingList.count)
return shoppingList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TestCell", forIndexPath: indexPath)
// Configure the cell...
cell.textLabel!.text = shoppingList[indexPath.row]
// Configure the cell...
print("here")
return cell
}
最佳答案
Julia,表格 View 似乎比屏幕本身长。如果您进入 Storyboard并缩短 tableview 的长度,您将能够看到其余部分,因为它与屏幕的尺寸相同或更短。
您可以添加约束,这些约束将自动捕捉以适应任何尺寸的屏幕。
如果你想通过代码来完成,在你的 viewDidLoad() 中试试这个
tableView.frame.size = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
关于ios - Swift UITableView 不显示所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33153074/