[英]why I don't see any cells in my UITableView in Swift?
我有一個UIViewController
,我把它放在TableView
:
我還在其中添加了UITableViewCell
,在故事板中檢查了我的表視圖是否具有動態生成的內容,並向UITableViewCell
添加了標識符“cell”。 我將它連接到我的類的插座,我從UITableViewDelegate
設置繼承:
class MapViewController: UIViewController, UITableViewDelegate, UITextViewDelegate {
@IBOutlet weak var myTableDetailsPanel: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
myTableDetailsPanel.delegate = self
}
然后我將我的自定義對象添加到我的數組:
var items = NSMutableArray()
...
print("size of items before: \(items.count)")
items.addObject(myObject)
print("size of items after: \(items.count)")
myTableDetailsPanel.reloadData()
myTableDetailsPanel.hidden = false
我也有這個方法:
func tableView(myTableDetailsPanel: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = myTableDetailsPanel.dequeueReusableCellWithIdentifier("cell") as! MyDetailsCell
let yawp:MySingleObject = self.items[indexPath.row] as! MySingleObject
print("hello")
...
而且......我的問題是面板顯示為空,在我看到的控制台中:
size of items before: 0
size of items after: 1
但不知怎的,我沒有看到hello
。 我的cellForRowAtIndexPath
代碼永遠不會運行。 為什么這樣?
當您實現UITableViewDelegate
協議以通知UITableView
更改時,您必須實現UITableViewDataSource
,數據源向表視圖對象提供構建和修改表視圖所需的信息。
所以你需要實現UITableViewDataSource
協議並將dataSource
聲明為self
如下所示:
myTableDetailsPanel.dataSource = self
我希望這對你有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.