日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

的界面跳转

發(fā)布時間:2023/11/30 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 的界面跳转 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在界面的跳轉有兩種方法,一種方法是先刪除原來的界面,然后在插入新的界面:如下代碼

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];

}

使用這種方式無法實現(xiàn)界面跳轉時的動畫效果。

另一中方式為將跳轉的界面的Controller放入到UINavigationController中,使用push或pop實現(xiàn)跳轉:使用這種方式可用實現(xiàn)動畫效果

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 創(chuàng)建一個基于Navigation-based Application的iphone工程,為什么要創(chuàng)建基于Navigation-based Application的工程呢,因為這樣系統(tǒng)就會自動將Navigation視圖加到我們的窗口視圖中,這樣我們就不用自己手動去加,并且可以用

[self.navigationControllerpushViewController:otherviewanimated:YES]去跳轉頁面。當設置每個頁面的標題后會在頁面左上角自動生成后退導航按鈕,多方便呀,當然需要在建立后將xib文件里面的tableview去掉加入view。

2 新建一個頁面,我這里是OtherView,讓系統(tǒng)自動生成.h,.xib文件。

3 第一個頁面上面添加一個文本筐和一個按鈕,點擊按鈕后調轉到第二個頁面并將文本筐里面的數(shù)據(jù)傳入第二個頁面。第二個頁面用一個label來顯示傳過來的數(shù)據(jù)。

4 代碼:

?首先是自動生成的協(xié)議里面的代碼,注意看navigationController

?

MynavAppDelegate.h代碼:

?

[html] view plaincopyprint?
  • #import?<UIKit/UIKit.h>??
  • ??
  • @interface?MynavAppDelegate?:?NSObject?<UIApplicationDelegate>?{??
  • ??
  • }??
  • ??
  • @property?(nonatomic,?retain)?IBOutlet?UIWindow?*window;??
  • ??
  • @property?(nonatomic,?retain)?IBOutlet?UINavigationController?*navigationController;??
  • ??
  • @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?
  • #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??
  • #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?
  • #import?<UIKit/UIKit.h> ??
  • #import?<Foundation/Foundation.h> ??
  • ??
  • @interface?RootViewController?:?UIViewController?{??
  • ????IBOutlet?UITextField?*?message;//需要傳出的數(shù)據(jù) ??
  • }??
  • ??
  • @property(nonatomic,retain)?UITextField?*?message;??
  • ??
  • -(IBAction)?send;//按鈕點擊方法 ??
  • ??
  • ??
  • @end??
  • #import <UIKit/UIKit.h> #import <Foundation/Foundation.h>@interface RootViewController : UIViewController {IBOutlet UITextField * message;//需要傳出的數(shù)據(jù) }@property(nonatomic,retain) UITextField * message;-(IBAction) send;//按鈕點擊方法@end


    RootViewController.m

    [cpp] view plaincopyprint?
  • #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??
  • #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?
  • #import?<UIKit/UIKit.h> ??
  • ??
  • ??
  • @interface?OtherView?:?UIViewController?{??
  • ????IBOutlet?UILabel?*?mylabel;//用來顯示傳入的數(shù)據(jù) ??
  • ????NSString?*?mystring;//數(shù)據(jù)傳入用到的屬性 ??
  • }??
  • ??
  • @property(nonatomic,retain)?UILabel?*?mylabel;??
  • @property(nonatomic,retain)?NSString?*?mystring;??
  • ??
  • ??
  • @end??
  • #import <UIKit/UIKit.h>@interface OtherView : UIViewController {IBOutlet UILabel * mylabel;//用來顯示傳入的數(shù)據(jù)NSString * mystring;//數(shù)據(jù)傳入用到的屬性 }@property(nonatomic,retain) UILabel * mylabel; @property(nonatomic,retain) NSString * mystring;@end

    OtherView.m

    [cpp] view plaincopyprint?
  • #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??
  • #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 orientationsreturn (interfaceOrientation == UIInterfaceOrientationPortrait); }@end





    ?

    總結

    以上是生活随笔為你收集整理的的界面跳转的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。