求助大神 如果我有一个路由像下面的那样 我如何得到destination呢 id<LivePlayerPublicInterface> destination = [_livePlayerViewRouter destination];会报错
KelyCocoa opened this issue · comments
KelyCocoa commented
- (ZIKDestinationViewRouter(id) )livePlayerViewRouter {
if (!_livePlayerViewRouter) {
_livePlayerViewRouter = [ZIKRouterToView(LivePlayerPublicInterface) performFromSource:self.routeSource configuring:^(ZIKViewRouteConfiguration * _Nonnull config) {
config.routeType = ZIKViewRouteTypeAddAsSubview;
config.prepareDestination = ^(id _Nonnull destination) {
[destination setFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenWidth3.0/4.0)];
};
}];
}
return _livePlayerViewRouter;
}
Zuik commented
You should not perform router in lazy getter. And you should not get destination from router directly, because the router only has weak reference to the destination, and the destination may not exist.
If you need to use the destination after performing route, you should hold the destination by yourself.
@interface TestViewController()
@property (nonatomic, strong) id<LivePlayerPublicInterface> livePlayerView;
@end
@implementation TestViewPresenter
- (void)addLivePlayerView {
__weak typeof(self) weakSelf = self;
[ZIKRouterToView(LivePlayerPublicInterface) performPath:ZIKViewRoutePath.addAsSubviewFrom(self.routeSource) configuring:^(ZIKViewRouteConfiguration *config) {
config.prepareDestination = ^(id destination) {
[destination setFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenWidth3.0/4.0)];
};
config.successHandler = ^(id destination) {
weakSelf.livePlayerView = destination;
};
}];
}
@end
KelyCocoa commented
谢谢大哥!爱你一万年!😄