我最近從UITableViewController
中簡單繼承了我的類BookTableViewController
,因此它現在繼承自其自身繼承的泛型類FetchedResultsTableViewController<TResultType, TCellType>
UITableViewController
。使用繼承自故事板中的泛型類的類時,「接口構建器文件中的未知類」
類的聲明是這樣的:
class BookTableViewController: FetchedResultsTableViewController<Book, BookTableViewCell> {
override func viewDidLoad() {
// breakpoints in here do not catch!
}
}
class FetchedResultsTableViewController<TResultType, TCellType: UITableViewCell>:
UITableViewController, NSFetchedResultsControllerDelegate {
// implementation here
}
在故事板,自定義類和模塊都設置了,我可以單擊箭頭跳轉到代碼爲BookTableViewController
類,提示故事板與班級正確鏈接。然而,當我嘗試運行應用程序時,類不能被識別 - 在viewDidLoad()
代碼不能運行,運行我的應用程序時,我收到以下記錄消息:在Interface Builder文件
未知類_TtC12Reading_List23BookTableViewController。
我正在運行XCode 7.3(Swift 2.2)。這是故事板的一個限制,一個錯誤,還是我錯過了什麼?
謝謝!
UPDATE:
一些實驗後,它似乎是相關的通用繼承,而不是類的可訪問性。隨着定義以下類:
import Foundation
import UIKit
// Both of these classes are accessible by the Storyboard
class FirstInheritance : UITableViewController{}
class SecondInheritance : FirstInheritance{}
// The generic class is also accessible
class GenericViewController<T> : UITableViewController{}
// But this class is not accessible...
class ConcreteViewController : GenericViewController<String>{}
除了ConcreteViewController
所有類都建議在故事板的類自動完成(儘管通用類也不起作用,因爲沒有辦法來指定在故事板的類型參數)。
故事板不知道FetchedResultsTableViewController嗎? –
根據您的評論,我注意到Storyboard中的Class字段_does_自動完成了'FetchedResultsTableViewController',但_does not_ autocomplete to'BookTableViewController'。 (當然,'FetchedResultsTableViewController'不起作用,因爲我們不能指定類型參數)。 我在問題的更新中創建了一個更簡單的行爲示例。另請參閱示例[這裏](https://github.com/AndrewBennet/GenericTableView)。我開始認爲這是故事板的限制... –
啊,是的,這是一個限制。基本上同樣的問題在這裏被問到:http://stackoverflow.com/a/32899800。我可能會嘗試使用帶有typealiases和擴展名的協議來代替默認行爲。 –