[英]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.