问题描述
我有一个泛型类:
pre $ pa $ pa $ pa
$其中Source.PaginatedGenericElement == GenericElement>:
UITableViewController
另一个我尝试实例化from storyboard:
类CandidatesTableViewController:
PaginatedTableViewController< Match,MatchPaginationDataSource>
我找不到 CandidatesTableViewController
故事板自定义类下拉菜单。如果我强制它,然后在代码中投我的控制器,应用程序崩溃在运行时抱怨我的控制器(这应该是一个CandidatesTableViewController实例)实际上是一个UITableViewController实例。
$ b
在我的项目中,这个控制器被嵌入到另一个中,这就是为什么我需要它:
tableViewController =( segue.destinationViewController as!CandidatesTableViewController)
有没有人知道如何解决这个问题?
不幸的是,通用的Swift类对于Objective-C代码是不可见的,而且在Interface Builder(故事板和xibs)中也不受支持。我发现这两点密切相关。作为一个解决方案,我建议你使用聚合:不要让你看到控制器通用,但提取一些逻辑到另一个(通用)类并在视图控制器中使用它。
I have a generic class:
class PaginatedTableViewController
<GenericElement, Source: PaginationDataSource
where Source.PaginatedGenericElement == GenericElement>:
UITableViewController
and another that I try to instantiate from storyboard:
class CandidatesTableViewController:
PaginatedTableViewController<Match, MatchPaginationDataSource>
I can't find CandidatesTableViewController
in the storyboard Custom Class dropdown menu. If I force it then cast my controller in code, app crashes at runtime complaining my controller (that should be a CandidatesTableViewController instance) is in fact a UITableViewController instance.
In my project this controller is embedded in another one that's why I cast it :
tableViewController = (segue.destinationViewController as! CandidatesTableViewController)
Does any one knows how to resolve this issue ?
Unfortunately, generic Swift classes are not visible to Objective-C code and also are not supported in Interface Builder (in storyboards and xibs). I find these two points closely related.
As a solution I would suggest you to use aggregation: do not make you view controller generic, but extract some logic to another (generic) class and use it inside your view controller.
这篇关于Xcode 7 Swift 2无法实例化通用UITableViewController的UIViewController子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!