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

查看:25
本文介绍了在 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 {
}

poo1ViewController.xib 中,我添加了一个按钮并使用 Interface Builder 将其与 File's Owner 链接.

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 视图?

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,单击设计区域左侧的File's Owner,并将类更改为UIViewController.现在按住 CTRL 从 File's Owner 图标拖动到它正下方的 View 图标,然后选择 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天全站免登陆