如何在UiView上添加New UIViewCOntroller

时间:2016-05-31 12:54:32

标签: ios uiview uiviewcontroller uibutton

我在subview添加了UIViewController,我想要一个新的UIViewController应该在点击按钮时加载。

挑战是我无法在新UIViewController中使用按钮。

我写的代码:

DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addSubview:aViewController.view];

2 个答案:

答案 0 :(得分:0)

要显示另一个控制器,您可以使用以下选项

<强> 1。添加子视图

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Quick Start</title>
</head>

<frameset onload="load()" rows="0,*" frameborder="0" border="0" framespacing="0">
    <frame name="topFrame" scrolling="no" src="../main/refresh.asp" __idm_frm__="200"></frame>
    <frame name="contentfrm" id="contentfrm" __idm_frm__="201"></frame>
</frameset>

</html>

<强> 2。本

 newViewControllerObj.view.frame = oldViewControllerObj(self).view.frame
  [oldViewControllerObj(self).view.newViewControllerObj.view];

第3。推送使用导航(为此您必须将导航控制器设置为根控制器)

  [oldViewControllerObj(self) presentViewController: newViewControllerObj animated:YES completion:nil];

答案 1 :(得分:0)

这将解决您的问题。这种情况正在发生,因为当您的视图控制器没有任何强大的指针时,您的视图控制器将被取消分配。

DetailsOfDayViewController *aViewController =[[DetailsOfDayViewController  alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
aViewController.dateParsing = dateparsing;
[self addChildViewController:aViewController];
[self addSubview:aViewController.view];

另一个修复方法是将此视图控制器连接到属性:

@property(nonatomic,strong) DetailsOfDayViewController *aViewController;

并改变你的代码:

self.aViewController = [[DetailsOfDayViewController  alloc] initWithNibName:@"DetailsOfDayViewController" bundle:nil];
self.aViewController.dateParsing = dateparsing;
[self addSubview:self.aViewController.view];