[英][UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance
[英]'NSInvalidArgumentException' - [UIViewController tableView:numberOfRowsInSection:] - unrecognized selector sent to instance
我知道這是一個重復的問題(非常抱歉),但是到目前為止,我已經嘗試了所有我發現的問題,但是仍然收到此錯誤的錯誤消息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fc4a9705960'
讓我用圖像清楚地闡明各部分,以便為解決相關問題提供一個很好的答案。
這是文件夾視圖( ViewController
主視圖, TableView1
是子視圖):
我的TableView1.xib
文件具有:
我還編輯了TableView1.swift
:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
在我的Main.Storyboard
:
當我選擇View Controller
( )看起來像這樣:
我在路上做錯了什么或想念什么?
更多信息:
-[UIViewController tableView:numberOfRowsInSection:]:
因此,根據錯誤日志,在設置deletegate和datasource時,某處的類型不匹配,這是因為在xib上您說tableview1.xib應該實現數據源和委托。但是在ViewController1.swift中,您錯誤地引用了UIViewController。 現在您看到UIViewController對於實現委托和數據源尚不為人所知,因為它沒有(顯然)崩潰。 所以:
let controller : UIViewController = UIViewController(nibName: "TableView1", bundle: nil)
變成:
let controller : UITableViewController = UITableViewController(nibName: "TableView1", bundle: nil)
應該管用。
您在其他地方調用過此功能嗎?
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
看起來除了委托以外,還調用了此函數。
沒有關於Swift的線索,但是iOS上的ObjC ...
異常表明,類UIViewController無法處理消息[UIViewController tableView:numberOfRowsInSection:]。 這表明,在某些時候,數據源已更改為“超級”。
您是否需要“替代”? 您不會覆蓋消息的實現,因為UIViewController不實現一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.