[英]How to call a UIViewController from a UIView SubClass?
我有主UIViewController
,其中有一个UITableView
。
在UItableView
的单元格中,我已经添加了UICollectionView
。
在-
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
我正在调用主UIViewController
的方法。
UIViewController *view = [[UIViewController alloc] init];
[view my_method];
在主要观点上。
-(void)my_method {
AnotherName *view_my=[[AnotherName alloc]initWithNibName:@"AnotherName" bundle:nil];
[self.navigationController pushViewController:view_my animated:NO];
}
Viewdidload
方法正在调用,但view
未显示。
这是因为您通过调用[[UIViewController alloc] init]
。 这总是返回空视图。
你应该叫这个
MainViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboard id"];
MainViewController *controller = [[MainViewController alloc] initWithNibName:@"Nib File Name" bundle:nil];
我有解决办法..
AnotherName *view_my = [[AnotherName alloc]initWithNibName:@"AnotherName" bundle:nil];
self.window.rootViewController = view_my;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
特别感谢@The Mech System
..为了帮助我找到解决方案..现在它可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.