2012-06-08 72 views
0

我正在申请Ipad.in这个应用程序我有一个UIButton在我的第一个类Xib,现在我想添加第二个类XIB在按钮click.i第一个类XIB我知道如何调用第二类XIB。这仅仅是这样的..我们如何在主类Xib中添加子类Xib?

-(IBAction)displaysecondclass 
{ 
secondview *sec=[[secondview alloc] initWithNibName:@"secondview" bundle:nil]; 
[self presentModalViewController:sec animated:YES]; 
[sec release]; 
} 

但我不想去二等,我需要显示上的firstView就这样第二类XIB。

-(IBAction)displaysecondclass 
{ 
secondview *sec=[[secondview alloc] initWithNibName:@"secondview" bundle:nil]; 
[self.view addSubView:sec]; 
} 

任何人都可以帮助我如何在第一个view.thanx预先添加第二类xib。

+0

uh ..huh?假设'first view',你的代码已经将'second class'视图添加到'self'中。不知道我明白你.. – skram

+0

是你确定secondview类xib文件名为secondview? – Dinesh

+0

@skram我不想要这样,我在第一个视图中添加第二课。 – jamil

回答

2

改变按钮代码

-(IBAction)displaysecondclass 
{ 
secondview *sec=[[secondview alloc] initWithNibName:@"secondview" bundle:nil]; 
[self.view addSubView:sec.view]; 
} 

请注意,您将需要添加额外的功能,一旦你不需要它了

+0

对不起,但我有点困惑。这种方法会在现有的视图上添加新的视图,对吧?或者它会替换第一个xib并添加新的视图?意味着它会被释放吗? –

+0

它会添加第二个视图作为你当前视图的子视图,它不会替换它:) –

+0

但是根据问题,他想替换不想添加的。 –

0

感谢名单为大家其实我的工作是兼职释放的ViewController IOS程序员。虽然它不是什么难事我在quesiton.i中提到的问题有点混淆,当我问这个问题是否与Subclass或newclass有关时,为什么我会发布Question.Thanx来帮助我。现在我使用这个链接得到了它的解决方案,可能对一些新的commer有所帮助。

http://www.roseindia.net/tutorial/iphone/examples/iPhone-Create-SubView.html