的界面跳转

在界面的跳转有两种方法,一种方法是先删除原来的界面,然后在插入新的界面:如下代码

if (self.rootViewController.view.superview == nil) {

[singleDollController.view removeFromSuperview];

[self.view insertSubview:rootViewController.view atIndex:0];

}

else {

[rootViewController.view removeFromSuperview];

[self.view insertSubview:singleDollController.view atIndex:0];

}

使用这种方式无法实现界面跳转时的动画效果。

另一中方式为将跳转的界面的Controller放入到UINavigationController中,使用push或pop实现跳转:使用这种方式可用实现动画效果

navController = [[UINavigationController alloc]init];

[navController setNavigationBarHidden:YES];

[window addSubview:navController.view];

rootView = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

[navController pushViewController:rootView animated:NO];

 

///

self.singleDollView = view;

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.5];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navController.view cache:NO];

[self.navController pushViewController:self.singleDollView animated:NO];

[UIView commitAnimations];

 

1 创建一个基于Navigation-based Application的iphone工程,为什么要创建基于Navigation-based Application的工程呢,因为这样系统就会自动将Navigation视图加到我们的窗口视图中,这样我们就不用自己手动去加,并且可以用

[self.navigationControllerpushViewController:otherviewanimated:YES]去跳转页面。当设置每个页面的标题后会在页面左上角自动生成后退导航按钮,多方便呀,当然需要在建立后将xib文件里面的tableview去掉加入view。

2 新建一个页面,我这里是OtherView,让系统自动生成.h,.xib文件。

3 第一个页面上面添加一个文本筐和一个按钮,点击按钮后调转到第二个页面并将文本筐里面的数据传入第二个页面。第二个页面用一个label来显示传过来的数据。

4 代码:

 首先是自动生成的协议里面的代码,注意看navigationController

 

MynavAppDelegate.h代码:

 

[html] view plaincopyprint?
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface MynavAppDelegate : NSObject <UIApplicationDelegate> {  
  4.   
  5. }  
  6.   
  7. @property (nonatomic, retain) IBOutlet UIWindow *window;  
  8.   
  9. @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;  
  10.   
  11. @end  
#import <UIKit/UIKit.h>
@interface MynavAppDelegate : NSObject <UIApplicationDelegate> {
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end


 

MynavAppDelegate.m代码:

[cpp] view plaincopyprint?
  1. #import "MynavAppDelegate.h"   
  2.   
  3. @implementation MynavAppDelegate  
  4.   
  5.   
  6. @synthesize window=_window;  
  7.   
  8. @synthesize navigationController=_navigationController;  
  9.   
  10. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  11. {  
  12.     self.window.rootViewController = self.navigationController;  
  13.     [self.window makeKeyAndVisible];  
  14.     return YES;  
  15. }  
  16.   
  17. - (void)applicationWillResignActive:(UIApplication *)application  
  18. {  
  19.      
  20. }  
  21.   
  22. - (void)applicationDidEnterBackground:(UIApplication *)application  
  23. {  
  24.      
  25. }  
  26.   
  27. - (void)applicationWillEnterForeground:(UIApplication *)application  
  28. {  
  29.       
  30. }  
  31.   
  32. - (void)applicationDidBecomeActive:(UIApplication *)application  
  33. {  
  34.      
  35. }  
  36.   
  37. - (void)applicationWillTerminate:(UIApplication *)application  
  38. {  
  39.       
  40. }  
  41.   
  42. - (void)dealloc  
  43. {  
  44.     [_window release];  
  45.     [_navigationController release];  
  46.     [super dealloc];  
  47. }  
  48.   
  49. @end  
#import "MynavAppDelegate.h"
@implementation MynavAppDelegate
@synthesize window=_window;
@synthesize navigationController=_navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
- (void)dealloc
{
[_window release];
[_navigationController release];
[super dealloc];
}
@end


第一个页面的代码:

RootViewController.h

[cpp] view plaincopyprint?
  1. #import <UIKit/UIKit.h>   
  2. #import <Foundation/Foundation.h>   
  3.   
  4. @interface RootViewController : UIViewController {  
  5.     IBOutlet UITextField * message;//需要传出的数据   
  6. }  
  7.   
  8. @property(nonatomic,retain) UITextField * message;  
  9.   
  10. -(IBAction) send;//按钮点击方法   
  11.   
  12.   
  13. @end  
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface RootViewController : UIViewController {
IBOutlet UITextField * message;//需要传出的数据
}
@property(nonatomic,retain) UITextField * message;
-(IBAction) send;//按钮点击方法
@end


RootViewController.m

[cpp] view plaincopyprint?
  1. #import "RootViewController.h"   
  2. #import "OtherView.h"   
  3.   
  4. @implementation RootViewController  
  5.   
  6. @synthesize message;  
  7.   
  8.   
  9. -(IBAction) send{  
  10.     OtherView  *otherview = [[OtherView alloc] initWithNibName:@"OtherView" bundle:nil];  
  11.       
  12.     otherview.mystring= message.text;  
  13.       
  14.     [self.navigationController pushViewController:otherview animated:YES];  
  15.       
  16.     [otherview release];  
  17. }  
  18.   
  19.   
  20. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
  21.       
  22.     UITouch *touch = [[event allTouches] anyObject];  
  23.       
  24.     if (touch.tapCount >= 1) {  
  25.           
  26.         [message resignFirstResponder];  
  27.           
  28.     }  
  29. }  
  30.   
  31. - (void)viewDidLoad  
  32. {  
  33.     self.title = @"第一个页面";  
  34.     [super viewDidLoad];  
  35. }  
  36.   
  37.   
  38. - (void)didReceiveMemoryWarning  
  39. {  
  40.     // Releases the view if it doesn't have a superview.   
  41.     [super didReceiveMemoryWarning];  
  42.       
  43.     // Relinquish ownership any cached data, images, etc that aren't in use.   
  44. }  
  45.   
  46. - (void)viewDidUnload  
  47. {  
  48.     [super viewDidUnload];  
  49.   
  50.     // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.   
  51.     // For example: self.myOutlet = nil;   
  52. }  
  53.   
  54. - (void)dealloc  
  55. {  
  56.     [message release];  
  57.     [super dealloc];  
  58. }  
  59.   
  60. @end  
#import "RootViewController.h"
#import "OtherView.h"
@implementation RootViewController
@synthesize message;
-(IBAction) send{
OtherView  *otherview = [[OtherView alloc] initWithNibName:@"OtherView" bundle:nil];
otherview.mystring= message.text;
[self.navigationController pushViewController:otherview animated:YES];
[otherview release];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (touch.tapCount >= 1) {
[message resignFirstResponder];
}
}
- (void)viewDidLoad
{
self.title = @"第一个页面";
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc
{
[message release];
[super dealloc];
}
@end


第二个页面代码:

OtherView.h

[cpp] view plaincopyprint?
  1. #import <UIKit/UIKit.h>   
  2.   
  3.   
  4. @interface OtherView : UIViewController {  
  5.     IBOutlet UILabel * mylabel;//用来显示传入的数据   
  6.     NSString * mystring;//数据传入用到的属性   
  7. }  
  8.   
  9. @property(nonatomic,retain) UILabel * mylabel;  
  10. @property(nonatomic,retain) NSString * mystring;  
  11.   
  12.   
  13. @end  
#import <UIKit/UIKit.h>
@interface OtherView : UIViewController {
IBOutlet UILabel * mylabel;//用来显示传入的数据
NSString * mystring;//数据传入用到的属性
}
@property(nonatomic,retain) UILabel * mylabel;
@property(nonatomic,retain) NSString * mystring;
@end

OtherView.m

[cpp] view plaincopyprint?
  1. #import "OtherView.h"   
  2.   
  3.   
  4. @implementation OtherView  
  5.   
  6. @synthesize mylabel,mystring;  
  7.   
  8.   
  9.   
  10. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  
  11. {  
  12.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  13.     if (self) {  
  14.         // Custom initialization   
  15.     }  
  16.     return self;  
  17. }  
  18.   
  19. - (void)dealloc  
  20. {  
  21.     [mylabel release];  
  22.     [mystring release];  
  23.     [super dealloc];  
  24. }  
  25.   
  26. - (void)didReceiveMemoryWarning  
  27. {  
  28.     // Releases the view if it doesn't have a superview.   
  29.     [super didReceiveMemoryWarning];  
  30.       
  31.     // Release any cached data, images, etc that aren't in use.   
  32. }  
  33.   
  34. #pragma mark - View lifecycle   
  35.   
  36. - (void)viewDidLoad  
  37. {  
  38.      
  39.     [super viewDidLoad];  
  40.      self.title = @"第二个页面";  
  41.     self.mylabel.text=mystring;  
  42.    // mylabel.text = mystring;   
  43.     // Do any additional setup after loading the view from its nib.   
  44. }  
  45.   
  46. - (void)viewDidUnload  
  47. {  
  48.     [super viewDidUnload];  
  49.     // Release any retained subviews of the main view.   
  50.     // e.g. self.myOutlet = nil;   
  51. }  
  52.   
  53. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  54. {  
  55.     // Return YES for supported orientations   
  56.     return (interfaceOrientation == UIInterfaceOrientationPortrait);  
  57. }  
  58.   
  59. @end  
#import "OtherView.h"
@implementation OtherView
@synthesize mylabel,mystring;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[mylabel release];
[mystring release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"第二个页面";
self.mylabel.text=mystring;
// mylabel.text = mystring;
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end





 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388375.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算性能提升100倍,Uber推出机器学习可视化调试工具

为了让模型迭代过程更加可操作&#xff0c;并能够提供更多的信息&#xff0c;Uber 开发了一个用于机器学习性能诊断和模型调试的可视化工具——Manifold。机器学习在 Uber 平台上得到了广泛的应用&#xff0c;以支持智能决策制定和特征预测&#xff08;如 ETA 预测 及 欺诈检测…

计算机应用基础成教作业,(计算机应用基础成教08A卷1.doc

一、判断题(每空1分&#xff0c;共10分&#xff0c;正确填A错误填B)1、计算机按照用途划分可以分为数字计算机、模拟计算机、数字模拟混合式计算机。()2、微型计算机就是指体积微小的计算机。()3、WindowsXP的窗口是不可改变大小的。( )4、操作系统是用户和计算机之间的接口。…

iPhone程序运行流程浅谈

1. 和大多数语言一样&#xff0c;每一个iPhone应用也都是从主函数开始运行&#xff0c;它的main函数都在XCode的Other Reasource逻辑目录下。 [cpp] view plaincopyprint?UIApplicationMain(argc, argv, nil, nil); [cpp] view plaincopyprint?UIApplicationMain(argc, arg…

Trie树kmpAC自动机后缀数组Manacher

Trie 计数Trie&#xff0c;读清题意很重要 https://vjudge.net/problem/UVALive-5913 kmp AC自动机 模板&#xff1a;https://vjudge.net/problem/UVA-11488 https://vjudge.net/problem/UVA-11019 https://vjudge.net/problem/UVA-11468 https://vjudge.net/problem/UVALive-4…

矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵

矩阵线性相关则矩阵行列式声明 (Statement) We have to search for a value x in a sorted matrix M. If x exists, then return its coordinates (i, j), else return (-1, -1).我们必须在排序的矩阵M中搜索值x 。 如果x存在&#xff0c;则返回其坐标(i&#xff0c;j) &#x…

计算机英文版个人简历发文,计算机个人简历英文_英文简历.doc

计算机个人简历英文_英文简历I have the honor to present a brief introduction of myself to you in compliance with the requirements of your graduate admissionI was born in November 7th, 1966, at the town of Changing, Beijing. My parents are doing business and…

一地鸡毛 OR 绝地反击,2019年区块链发展指南

如果盘点2018年IT技术领域谁是“爆款流量”,那一定有个席位是属于区块链的,不仅经历了巨头、小白纷纷入场的光辉岁月,也经历了加密货币暴跌,争先退场的一地鸡毛。而当时间行进到2019年,区块链又将如何发展呢? 近日,全球知名创投研究机构CBInsight发布了《What’s Next …

iphone UITableView及UIWebView的使用

1。新建一个基于Navigation&#xff0d;based Application的工程。 2。修改原来的RootViewController.h,RootViewController.m,RootViewController.xib为MyTableViewController.h,MyTableViewController.m,MyTableViewController.xib。 3。点击MainVindow.xib&#xff0c;将R…

python 的datetime模块使用

1.datetime模块主要是5个类 date #日期类 年月日 datetime.date(year,month,day) time #时间类 时分秒 datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30 datetime #日期时间类 datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinf…

物联网数据可视化_激发好奇心:数据可视化如何增强博物馆体验

物联网数据可视化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

计算机公开课教学反思,语文公开课教学反思

语文公开课教学反思引导语&#xff1a; 在语文的公开课结束后&#xff0c;教师们在教学 有哪些需要反思的呢?接下来是yjbys小编为大家带来的关于语文公开课教学反思&#xff0c;希望会给大家带来帮助。篇一&#xff1a;语文公开课教学反思今天早上&#xff0c;我上了一节语文…

中国连续十年成马来西亚最大贸易伙伴

中新社吉隆坡1月30日电 (记者 陈悦)马来西亚国际贸易和工业部30日发布的2018年马来西亚贸易报告显示&#xff0c;2018年马来西亚与中国的贸易额约为3138.1亿林吉特(马来西亚货币&#xff0c;约合774亿美元)&#xff0c;较上年同期增长8.1%&#xff0c;约占马来西亚对外贸易总额…

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

一.NSMutableDictionary NSMutableDictionary * tags&#xff1b; 1.NSMutableDictionary 添加内容&#xff1a; [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍历&#xff1a; for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…

bzoj2938: [Poi2000]病毒

被Star_Feel大爷带着做题 明显大力AC机然后找环 本来我一开始想的是先去有另一个病毒为前缀的病毒&#xff0c;结果今天早上写的时候偷懒没写 结果跳fail的时候会跳到中间。。。无语&#xff0c;Star_Feel大爷叫我son或一下now和fail就过了 还有神仙是直接把fail接到儿子的更流…

bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程

bigquery数据类型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中国计算机学科建设,计算机学科建设战略研讨会暨“十四五”规划务虚会召开...

4月15日下午&#xff0c;信息学院计算机系举办了计算机科学与技术学科建设战略研讨会暨“十四五”规划务虚会。本次会议的主旨是借第五轮学科评估的契机&#xff0c;总结计算机学科发展的优劣势&#xff0c;在强调保持优势的同时&#xff0c;更着眼于短板和不足&#xff0c;在未…

iphone开发如何隐藏各种bar

转载至&#xff1a;http://blog.csdn.net/riveram/article/details/7291142 状态条StatusBar [cpp] view plaincopyprint?[UIApplication sharedApplication].statusBarHidden YES; [UIApplication sharedApplication].statusBarHidden YES; 导航条NavigationBar [cpp] v…

Swift5.1 语言指南(九) 闭包

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号&#xff1a;山青咏芝&#xff08;shanqingyongzhi&#xff09;➤博客园地址&#xff1a;山青咏芝&#xff08;https://www.cnblogs.com/strengthen/&#xff09;➤GitHub地址&a…

服务器被攻击怎么修改,服务器一直被攻击怎么办?

原标题&#xff1a;服务器一直被攻击怎么办&#xff1f;有很多人问说&#xff0c;网站一直被攻击&#xff0c;什么被挂马&#xff0c;什么被黑&#xff0c;每天一早打开网站&#xff0c;总是会出现各种各样的问题&#xff0c;这着实让站长们揪心。从修改服务器管理账号开始&…

脚本 api_从脚本到预测API

脚本 apiThis is the continuation of my previous article:这是我上一篇文章的延续&#xff1a; From Jupyter Notebook To Scripts从Jupyter Notebook到脚本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…