我有UITableView连接到一个数组。 var shoppingList:[String] = [" Eggs"," Milk"," A"," B"," C&# 34;," d"" E"" F"" G"" H"&# 34; I"" J"" K"" L"" M"" N&#34 ;," O"] 但是,当我在模拟器中运行应用程序时,它不允许我滚动到结尾。这是为什么?我只能滚动到字母"我"看到" 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
}
答案 0 :(得分:0)
朱莉娅,似乎桌面视图比屏幕本身更长。如果你进入你的故事板并缩短你的桌面视图的长度,你将能够看到其余部分,因为它是相同或更短的屏幕尺寸。
您可以添加约束,这些约束将自动捕捉到适合任何大小的屏幕。
如果您想通过代码执行此操作,请在viewDidLoad()
中尝试此操作 tableView.frame.size = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)