在iOS中按下按钮时打开另一个视图 [英] Open another view when button is pressed in iOS

查看:295
本文介绍了在iOS中按下按钮时打开另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iOS开发完全陌生,我想在当前视图中按下按钮时加载另一个视图。

I am completely new to iOS development and I want to load another view when a button is pressed in a present view.

我创建了一个基于视图的应用程序以下是代码:

I have created a view based application and following are the codes:

//我的文件名是poo1

//My file name is poo1

//这是poo1ViewController.h文件

//This is poo1ViewController.h file

#import <UIKit/UIKit.h>
@interface poo1ViewController : UIViewController 
{
 IBOutlet UIButton *fl;
}
@property (nonatomic,retain) UIButton *fl;
-(IBAction) ifl:(id)sender;    
@end

//这是poo1ViewController.m文件

//This is poo1ViewController.m file

#import "poo1ViewController.h"
@implementation poo1ViewController
@synthesize fl;
-(IBAction) ifl:(id) sender {
}

In poo1ViewController.xib 我添加了一个按钮,并使用Interface Builder将其与File的所有者链接。

In the poo1ViewController.xib I have added a button and linked it with File's Owner using Interface Builder.

现在我有了为此类添加了另一个视图,名为 flip.xib ,只是在其中添加了一个标签。

Now I have added another view to this class called as flip.xib an just added a label inside it.

我想要的是,当我按下 fl 按钮时, fl 按钮将调用 ifl 方法,并且该方法应调用第二个视图,即 flip.xib

The thing I want is, when I will press the fl button, the fl button will call the method ifl and which in return should call the second view, i.e. flip.xib.

我如何做到这一点,如何使 ifl 方法加载 flip.xib view?

How will I do that, how can I make the ifl method to load flip.xib view ?

推荐答案

UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip.xib" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];

编辑:

UIViewController* flipViewController = [[UIViewController alloc] initWithNibName:@"flip" bundle:[NSBundle mainBundle]];
[self.view addSubview:flipViewController.view];

现在点击flip.xib,点击设计区左侧的文件所有者,并将类更改为UIViewController。现在,CTRL从文件的所有者图标拖动到它下方的视图图标,然后选择IBOutlet视图。

Now click on flip.xib, click on the File's Owner on the left hand side of the design area, and change the class to UIViewController. Now CTRL drag from File's Owner icon to the View icon right below it and select the IBOutlet View.

这篇关于在iOS中按下按钮时打开另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆