[英]UITableView scrolls horizontally on iOS7 when loading Cell from Nib?
我創建了一個UITableViewController
子類:
class RootTableViewController: UITableViewController {
private let cellIdentifier = "MyCell2"
private let cellNibName = "MyCell2"
private var itemList: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
for i in 0..<1000 {
itemList.append("T\(i)")
}
let nib = UINib(nibName: cellNibName, bundle: nil)
self.tableView.registerNib(nib, forCellReuseIdentifier: cellIdentifier)
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! MyCell2
return cell
}
MyCell2
是UITableViewCell
的子類:
class MyCell2: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
MyCell2.xib在其ContentView
包含一個UIButton。 UITableViewCell的標識符設置為MyCell2
,而Class設置為MyCell2
。
當我在iOS8上運行該應用程序時,一切正常。 沒有水平滾動。 當我在iOS7上運行該應用程序時,會發生水平滾動:
如何防止iOS7中的表格水平滾動?
編輯:我的UITableView
xib配置是:
您的xib文件/故事板中是否有此UITableView配置?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.