我有UITableView掛鉤到一個數組。 「雞蛋」,「牛奶」,「A」,「B」,「C」,「D」,「E」,「F」,「G」,「H」,「 I「,」J「,」K「,」L「,」M「,」N「,」O「] 但是,當我在模擬器中運行應用程序時,它不允許我滾動到結尾。這是爲什麼?我只能滾動到字母「I」,看到「J」的一半,但我無法進一步向下滾動。在func tableView中,它顯示正確的數組大小,所以我知道這些項目都在那裏,但不能滾動到最後。以下是屏幕截圖。謝謝。 screen shot screen shot 2Swift UITableView不顯示所有結果
這裏的代碼
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
你在哪裏設置tableView的大小?如果tableview比屏幕長,你將不會看到最後幾個元素 –