我有主 UIViewController
,其中有一个 UITableView
。
在 UItableView
的单元格中,我已经添加了一个 UICollectionView
。
在 -
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
我正在调用 main 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]
进行了初始化。这总是返回空 View 。
你应该改为调用它
- 如果你使用 Storyboard,给 View Controller 一个 Storyboard ID 并调用它
MainViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboard id"];
- 如果您使用界面构建器,请调用它
MainViewController *controller = [[MainViewController alloc] initWithNibName:@"Nib 文件名"bundle:nil];
关于ios - 如何从 UIView 子类调用 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37943640/