简体   繁体   English

如何在UiView上添加新的UIViewCOntroller

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

相关问题 如何将半透明的UIView添加到UIViewController - How to Add a Semi Transparent UIView to a UIViewController 在UIViewController上方添加UIView - Add `UIView` above `UIViewController` 通过UIViewController以编程方式实现UIView - Implementing programmatically UIView over a UIViewController 以编程方式向UIView或UIViewController添加约束? - Programmatically add constraints to UIView or UIViewController? UIView不会添加到UIViewController - UIView doesn't add to UIViewController 将渐变层添加到uiviewcontroller uiview - Add gradient layer to uiviewcontroller uiview 如何仅在一个UIViewController中将自定义UIView添加到UINavigationBar - How to add a custom UIView to UINavigationBar in only one UIViewController 如何添加UIViewController作为在以编程方式创建的UIView中创建的UIButton操作的目标? - How to add UIViewController as target of UIButton action created in programmatically created UIView? 如何将两个带有内部集合视图的 UIView 添加到 UIViewController - How to add two UIView with collection view inside to UIViewController 如何在 UIView 子类中通过 UIView 约束 UITableView 并在 UIViewController 中保留数据源和委托方法? - How to constraint UITableView over UIView in UIView subclass and keep dataSource and delegate methods in UIViewController?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM