【发布时间】:2015-10-15 15:51:33
【问题描述】:
我将 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
}
【问题讨论】:
-
如果您不发布代码,我们如何帮助您?
-
谢谢,我刚刚发布了代码。
-
tableView的大小在哪里设置?如果 tableview 比屏幕长,您将看不到最后几个元素
-
为什么要在 Swift 问题中标记objective-c?
-
如何设置tableView的大小?我把它放在视图控件中。我上传了另一个布局的屏幕截图。抱歉,因为我认为这更像是一个 UI 问题而不是代码,并且由于对象 c 使用相同的 UI,我不妨标记它。
标签: ios swift uitableview storyboard