[英]how to add New UIViewCOntroller Over UiView
I have added subview
in a UIViewController
and I want a new UIViewController
Should be loaded on click of button. 我在
UIViewController
添加了subview
,并且我希望在单击按钮时加载一个新的UIViewController
。
Challenge is I am not able to use button in new UIViewController
. 挑战是我无法在新的
UIViewController
使用按钮。
Code which I have write: 我写的代码:
DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addSubview:aViewController.view];
For showing another controller you can following options 要显示另一个控制器,您可以选择以下选项
1. Add SubView 1.添加子视图
newViewControllerObj.view.frame = oldViewControllerObj(self).view.frame
[oldViewControllerObj(self).view.newViewControllerObj.view];
2. Present 2.礼物
[oldViewControllerObj(self) presentViewController: newViewControllerObj animated:YES completion:nil];
3. Push using Navigation (For this you already have to set navigation controller as root controller) 3.使用导航进行推送 (为此,您已经必须将导航控制器设置为根控制器)
[oldViewControllerObj(self).navigationController pushViewController:newViewControllerObj animated:YES];
This will fix your issue. 这样可以解决您的问题。 This is happening because your view controller is being deallocated when you don't have any strong pointers on it.
发生这种情况的原因是,当您的视图控制器上没有任何强大的指针时,就会对其进行释放。
DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addChildViewController:aViewController];
[self addSubview:aViewController.view];
Another fix will be connecting this view controller to a property: 另一个修复方法是将此视图控制器连接到属性:
@property(nonatomic,strong) DetailsOfDayViewController *aViewController;
And change your code like this: 并像这样更改代码:
self.aViewController = [[DetailsOfDayViewController alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
self.aViewController.dateParsing = dateparsing;
[self addSubview:self.aViewController.view];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.