navigationuialertcontrollerr怎么push到另一个navigationuialertcontrollerr

在没有navigationController的情况下,要从一个ViweController切换到另一个ViewController应该()_牛客网
在没有navigationController的情况下,要从一个ViweController切换到另一个ViewController应该()
{self navigationController pushViewController:nextViewController animated:YES};
{self view addSubview:nextViewController.view};
{self presentModalViewController:nextViewController animated:YES};
{self pushViewController:nextViewController animated:YES};
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网iOS_18_控制器切换_NavigationController_push方式_传递数据 - 推酷
iOS_18_控制器切换_NavigationController_push方式_传递数据
最终效果图:
storyboard示意图:
BeyondViewController.h
BeyondViewController.h
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &UIKit/UIKit.h&
@interface BeyondViewController : UIViewController
// NavigationItem左侧的按钮
@property (weak, nonatomic) IBOutlet UIBarButtonItem *refreshB
// NavigationItem右侧的按钮
@property (weak, nonatomic) IBOutlet UIBarButtonItem *wantToLoginB
// NavigationItem左侧的按钮 点击事件 刷新至初始状态
- (IBAction)refresh:(UIBarButtonItem *)
BeyondViewController.m
BeyondViewController.m
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &BeyondViewController.h&
@interface BeyondViewController ()
@implementation BeyondViewController
// 刷新至初始状态
- (IBAction)refresh:(UIBarButtonItem *)sender
self.navigationItem.title = @&首页&;
self.wantToLoginBtn.enabled = YES;
self.refreshBtn.enabled = NO;
LoginViewController.h
LoginViewController.h
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &UIKit/UIKit.h&
@interface LoginViewController : UIViewController
// 用户名输入框
@property (weak, nonatomic) IBOutlet UITextField *
// 密码输入框
@property (weak, nonatomic) IBOutlet UITextField *
// 输入用户名和密码之后,点击 登录按钮
- (IBAction)loginBtnClick:(UIButton *)
// NavigationItem左侧的按钮 点击事件
返回前一个控制器
- (IBAction)backToHome:(UIBarButtonItem *)
LoginViewController.m
LoginViewController.m
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &LoginViewController.h&
#import &NanaViewController.h&
@interface LoginViewController ()
@implementation LoginViewController
- (void)viewDidLoad
[super viewDidLoad];
_password.secureTextEntry = YES;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
#pragma mark - Navigation
// 在通过segue跳转至下一个导航子控制器前,做准备工作!这儿是传递数据给目的控制器
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)username
// 要得到目的控制器,请使用 [segue destinationViewController].
// 在这里,可以传递数据给下一个控制器
// 这个参数是要传递的数据
NSLog(@&prepare for segue----%@&,username);
// 通过segue的destinationViewController得到即将要跳转的目的控制器,传递数据给它
NanaViewController *nanaVC = [segue destinationViewController];
NSString *oldTitle = nanaVC.item_nanaSay.
nanaVC.username =
NSString *newStr = [NSString stringWithFormat:@&%@你好呀~%@
&,username,oldTitle];
nanaVC.item_nanaSay.title = newS
// 输入用户名和密码之后,点击 登录按钮
- (IBAction)loginBtnClick:(UIButton *)sender
// robust判断
if (_username.text.length == 0 || _password.text.length == 0) {
UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@&请输入帐号和密码& delegate:nil cancelButtonTitle:@&取消& destructiveButtonTitle:@&明白& otherButtonTitles:@&other&, nil];
[sheet showInView:self.view];
[_username becomeFirstResponder];
// 输入正确的密码和账号之后,跳转至第3个控制器
// self.navigationController pushViewController:&#(UIViewController *)#& animated:&#(BOOL)#&
// 通过segue连线,跳至self.navigationController容器里面的下一个 子控制器,并且传递参数(用户名),参数会被传递到self的 prepareForSegue方法中,然后才会传递到 下一下控制器(destination)
[self performSegueWithIdentifier:@&segue_loginSuccess& sender:_username.text];
// NavigationItem左侧的按钮 点击事件
返回前一个控制器,即首页
- (IBAction)backToHome:(UIBarButtonItem *)sender
[self.navigationController popViewControllerAnimated:YES];
NanaViewController.h
NanaViewController.h
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &UIKit/UIKit.h&
@interface NanaViewController : UIViewController
// NavigationItem右侧的按钮
@property (weak, nonatomic) IBOutlet UIBarButtonItem *item_nanaS
// 点击NavigationItem左侧的按钮
回到首页,即第一个控制器,并且将数据带过去
- (IBAction)backToHome:(UIBarButtonItem *)
// 仅用来接收传递过来的数据用~
@property (nonatomic,copy) NSString *
NanaViewController.m
NanaViewController.m
18_控制器切换_navigation_push_通过storyboard方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &NanaViewController.h&
#import &BeyondViewController.h&
@interface NanaViewController ()
@implementation NanaViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
// 回到首页,即第一个控制器,并且将数据带过去
- (IBAction)backToHome:(UIBarButtonItem *)sender {
// 拿到第一个控制器
BeyondViewController *firstVC = [self.navigationController.viewControllers firstObject];
// [self.navigationController.viewControllers objectAtIndex:n-2];
//n為最頂的index
//加入要传递的数据
NSString *str = [NSString stringWithFormat:@&欢迎%@回来&,_username];
firstVC.navigationItem.title =
firstVC.wantToLoginBtn.enabled = NO;
firstVC.refreshBtn.enabled = YES;
// pop至第一个控制器
[self.navigationController popToViewController:firstVC animated:YES];
========================
**************
我是分割线
**************
=================================
push的实现,使用代码方式:
BeyondAppDelegate.h
BeyondAppDelegate.h
18_控制器切换_navigationCtrl_push_代码方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &UIKit/UIKit.h&
@class BeyondViewC
@interface BeyondAppDelegate : UIResponder &UIApplicationDelegate&
@property (strong, nonatomic) UIWindow *
// 为应用程序的代理 添加一个成员属性
@property (nonatomic,strong) BeyondViewController *viewC
BeyondAppDelegate.m
BeyondAppDelegate.m
18_控制器切换_navigationCtrl_push_代码方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &BeyondAppDelegate.h&
#import &BeyondViewController.h&
@implementation BeyondAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
===============================对比 原版
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// 为应用代理 的成员属性 实例化一个BeyondViewController控制器
self.viewController = [[BeyondViewController alloc] initWithNibName:@&BeyondViewController& bundle:nil];
// 将BeyondViewController控制器,设置成为窗口的rootViewController
self.window.rootViewController = self.viewC
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
&pre name=&code& class=&objc&&===============================对比 原版 &span style=&font-family: Arial, Helvetica, sans-&&*/&/span&
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // 为应用代理 的成员属性 实例化一个BeyondViewController控制器 self.viewController = [[BeyondViewController alloc] initWithNibName:@&BeyondViewController& bundle:nil]; // 创建导航控制器,并设置 栈底的控制器为 BeyondViewController UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:self.viewController]; // 最后将导航 控制器,设置成为窗口的rootViewController self.window.rootViewController = self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES;}@end
BeyondViewController.m
BeyondViewController.m
18_控制器切换_navigationCtrl_push_代码方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
导航控制器方法总结:
1,创建导航控制器,在App代理的方法里面
// 创建导航控制器,并设置 栈底的控制器为 BeyondViewController
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:self.viewController];
2,栈 的形式管理
self.navigationController.viewControllers
3,压栈 即跳至下一个控制器
[self.navigationController pushViewController:loginVC animated:YES];
4,出栈 即返回,将控制器从stack里面弹出
[self.navigationController popToRootViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController popToViewController:&#(UIViewController *)#& animated:&#(BOOL)#&];
5,导航栏显示标题,左Item,右item,返回item
其中 返回的文本是由上一个控制器决定 的 ???
self.title 就是 self.navigationItem.title
6,取得栈顶控制器
self.navigationController.topViewController
#import &BeyondViewController.h&
#import &LoginViewController.h&
@interface BeyondViewController ()
@implementation BeyondViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
- (void)viewDidLoad
[super viewDidLoad];
// 设置顶部标题
self.navigationItem.title = @&首页&;
// 设置右边的按钮和点击事件
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@&下一张& style:UIBarButtonItemStyleBordered target:self action:@selector(nextBtnClick)];
// 点击 下一张,进入 下一个控制器
- (void)nextBtnClick
// 实例化,下一个控制器,并push添加到父容器中,并动画跳转
LoginViewController *loginVC = [[LoginViewController alloc]init];
这样子也可以拿到容器控制器,即导航控制器[self.parentViewController];
[self.navigationController pushViewController:loginVC animated:YES];
BeyondViewController.xib
第2个控制器.m
LoginViewController.m
18_控制器切换_navigationCtrl_push_代码方式
Created by beyond on 14-7-31.
Copyright (c) 2014年 com.beyond. All rights reserved.
#import &LoginViewController.h&
#import &NanaViewController.h&
@interface LoginViewController ()
@implementation LoginViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
- (void)viewDidLoad
[super viewDidLoad];
// 设置顶部标题
self.navigationItem.title = @&料理&;
// 设置返回按钮的显示 文本
self.navigationItem.backBarButtonItem.title = @&上一张&;
//设置顶部 右边的按钮,并添加监听事件
UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@&下一张& style:UIBarButtonItemStyleBordered target:self action:@selector(rightBtnClick)];
self.navigationItem.rightBarButtonItem =
// 响应 顶部 右边的 点击
- (void)rightBtnClick
// 实例化,第3个控制器,并push至栈顶
// 实例化,下一个控制器,并push添加到父容器中,并动画跳转
NanaViewController *nanaVC = [[NanaViewController alloc]init];
这样子也可以拿到容器控制器,即导航控制器[self.parentViewController];
[self.navigationController pushViewController:nanaVC animated:YES];
已发表评论数()
&&登&&&陆&&
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见iphone-69-定义NavigationController&pop&和push的动画
系统默认的NavigationController还不错,但是时间长了会有审美疲劳,今天在网上找了找资料,改变默认的动画效果。
1.添加QuartzCore并引入头文件&
&QuartzCore/CoreAnimation.h&
2. PushView 的动画修改&
&CATransition&*transition&=&[CATransition&animation];
&&&&&&&&transition.duration&=&1;
&&&&&&&&transition.timingFunction&=&[CAMediaTimingFunction&functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
&&&&&&&&transition.type&=&kCATransitionP
&&&&&&&&transition.subtype&=&kCATransitionFromT
&&&&&&&&transition.delegate&=&
&&&&&&&&[self.navigationController.view.layer&addAnimation:transition&forKey:nil];
&&&&&&&&self.navigationController.navigationBarHidden&=&NO;
[self.navigationController&pushViewController:viewController&animated:NO];&
3.popView的动画
CATransition&*transition&=&[CATransition&animation];
&&&&transition.duration&=0.4;
&&&&transition.timingFunction&=&[CAMediaTimingFunction&functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
&&&&transition.type&=&kCATransitionR
&&&&//transition.subtype&=&kCATransitionFromB
&&&&transition.delegate&=&
&&&&[self.navigationController.view.layer&addAnimation:transition&forKey:nil];
&&&&self.navigationController.navigationBarHidden&=&NO;
[self.navigationController&popViewControllerAnimated:NO];&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。Swift 初體驗 part.5 —How to use UINavigationcontroller | iKevin 開發筆記
接下來我們就要簡單地練習Swift的UINavigationcontroller,程式大同小異,只是換成Swift的語法。
首先New一個Project,選擇 Empty Application
輸入專案名稱:NavDemo
點「Next」之後,新的專案就被建立了。
新增一個 Cocoa Touch Class
選擇UIViewController 類型,名稱為:RootViewController
點「Next」之後,新的UIViewController就被建立了。
將RootViewController 置入 AppDelegate 的window 裡。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -& Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
// 設定rootViewController
let rvc=RootViewController(nibName:&RootViewController&,bundle:nil);
let nav=UINavigationController(rootViewController: rvc);
self.window!.rootViewController=
self.window!.backgroundColor = UIColor.whiteColor()
self.window!.makeKeyAndVisible()
return true
RUN一下,測試看看有沒有bugs....
打開 RootViewController.swift,你會看到三個 func
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
// Custom initialization
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
針對 viewDidLoad() 開始設定 UINavigationController
override func viewDidLoad() {
super.viewDidLoad()
//設定標題
self.title=&NavDeom&;
//設定左邊的按鈕
let leftButton=UIBarButtonItem();
leftButton.title=&左邊&;
leftButton.style=UIBarButtonItemStyle.P
leftButton.target=
leftButton.action=Selector(&left&);//必須實作 left()
self.navigationItem.leftBarButtonItem=leftB
//設定右邊的按鈕
let rightButton=UIBarButtonItem(title:&右邊&,style:UIBarButtonItemStyle.Done,target:self,action:Selector(&right&));
//必須實作right()
self.navigationItem.rightBarButtonItem=rightB
// Do any additional setup after loading the view.
func left(){
println(&left&);
func right(){
println(&right&);
RUN一下,測試看看有沒有bugs....
實作UINavigationController 的切換,新增兩個 UIViewController,分別為 LeftViewController,RightViewController
撰寫 left(),right() 的內容
func left(){
println(&left&);
let lvc=LeftViewController(nibName:&LeftViewController&,bundle:nil);
self.navigationController.pushViewController(lvc, animated: true);
func right(){
println(&right&);
let rvc=RightViewController(nibName:&RightViewController&,bundle:nil);
self.navigationController.pushViewController(rvc,animated:true);
RUN一下,測試看看有沒有bugs....
分類: | 日期: | 作者:

我要回帖

更多关于 uiviewcontroller 的文章

 

随机推荐