Iphone多个view之间跳转传值[登陆]

简介:

在第一个界面登陆,在第二个界面显示名字,并且根据不同的名字显示不同的图片 (最好不要加toolbar)

效果图:


单例Number.h:

#import <Foundation/Foundation.h>

@interface Number : NSObject

{

    NSString *name;

    NSString *password;

}

@property(nonatomic,retain)NSString *name;

@property(nonatomic,retain)NSString *password;

+(Number *)getNumber;

@end


Number.m:

#import "Number.h"


@implementation Number

+(Number *)getNumber

{

    static Number * a;

    if (a == Nil) {

        a = [Number alloc];

    }

    return a;

}

@end


DXWViewController.h:

#import <UIKit/UIKit.h>

@class BlueViewController;

@class YellowViewController;

@interface DXWViewController : UIViewController

@property(retain,nonatomic)BlueViewController *blueViewController;

@property(retain,nonatomic)YellowViewController *yellowViewController;

- (IBAction)blueClick:(id)sender;

- (IBAction)yellowClick:(id)sender;

- (IBAction)redClick:(id)sender;

- (IBAction)click:(id)sender;

- (IBAction)btnOK:(id)sender;

- (IBAction)btnCancel:(id)sender;

@property (retainnonatomicIBOutlet UITextField *txtName;

@property (retainnonatomicIBOutlet UITextField *txtPassword;

//退出键盘

- (IBAction)returnBoard:(id)sender forEvent:(UIEvent *)event;

@end


DXWViewController.m:

#import "DXWViewController.h"

#import "Number.h"

#import "BlueViewController.h"

#import "YellowViewController.h"

@interface DXWViewController ()


@end


@implementation DXWViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [superviewDidLoad];

}

//如果内存警告,则调用这个方法,可以让你自己清掉一些不需要用的内存

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    NSLog(@"内存告急");

    //如果内存警告则释放无用资源

    if (self.blueViewController.view.superview != nil) {

        [self.yellowViewController.viewremoveFromSuperview];

    }

    elseif(self.yellowViewController.view.superview != nil){

        [self.blueViewController.viewremoveFromSuperview];

    }

}

- (IBAction)click:(id)sender {

   // NSLog(@"hello");

    [UIView beginAnimations:@"anim"context:nil];

    //一个动画的持续时间

    [UIView setAnimationDuration:1.5f];

    //一个动画的运动随时间快慢曲线

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //动画方式

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeftforView:self.viewcache:YES];

    //如果当前view的父view存在

    if (self.blueViewController.view.superview != nil) {

        //如果没创建则创建

        if (self.yellowViewController ==nil) {

            self.yellowViewController = [[[YellowViewControlleralloc]initWithNibName:@"YellowViewController"bundle:nil]autorelease];

        }

        [self.blueViewController.viewremoveFromSuperview];

        [self.viewinsertSubview:self.yellowViewController.viewatIndex:10];

    }

    

    elseif (self.yellowViewController.view.superview != nil) {

//        [UIView beginAnimations:@"anim" context:nil];

//        //一个动画的持续时间

//        [UIView setAnimationDuration:2.5f];

//        //一个动画的运动随时间快慢曲线

//        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

        //动画方式

        [UIView setAnimationTransition:UIViewAnimationOptionTransitionCurlUpforView:self.viewcache:YES];

        //如果没创建则创建

        if (self.blueViewController ==nil) {

            self.blueViewController = [[[BlueViewControlleralloc]initWithNibName:@"BlueViewController"bundle:nil]autorelease];

        }

        [self.yellowViewController.viewremoveFromSuperview];

        [self.viewinsertSubview:self.blueViewController.viewatIndex:10];

        [UIView commitAnimations];

    }

    //动画效果启动

    [UIView commitAnimations];

}


- (IBAction)btnOK:(id)sender {

    [UIView beginAnimations:@"anim"context:nil];

    //一个动画的持续时间

    [UIView setAnimationDuration:1.5f];

//    //一个动画的运动随时间快慢曲线

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //动画方式

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];

    [Number getNumber].name =self.txtName.text;

    [Number getNumber].password =self.txtPassword.text;

    self.blueViewController = [[[BlueViewControlleralloc]initWithNibName:@"BlueViewController"bundle:nil]autorelease];

    [self.viewinsertSubview:self.blueViewController.viewatIndex:10];

    self.txtName.text =@"";

    self.txtPassword.text =@"";

    [self.txtPasswordresignFirstResponder];

    [self.txtNameresignFirstResponder];

//    if (self.txtName == @"apple") {

//        self.blueViewController.img2.hidden = YES;

//    }

//    else if (self.txtName == @"dog"){

//        self.blueViewController.img.hidden = YES;

//    }

//    else

//    {

//        self.blueViewController.img2.hidden = YES;

//        self.blueViewController.img.hidden = YES;

//    }

    self.blueViewController.img2.hidden =YES;

    self.blueViewController.img.hidden =YES;

    //动画效果启动

    [UIView commitAnimations];

}


- (IBAction)btnCancel:(id)sender {

    [self.txtPasswordresignFirstResponder];

    [self.txtNameresignFirstResponder];

    self.txtName.text =@"";

    self.txtPassword.text =@"";

}

- (IBAction)blueClick:(id)sender {

    NSLog(@"blue");

    [self.blueViewController.viewremoveFromSuperview];

    self.blueViewController = [[[BlueViewControlleralloc]initWithNibName:@"BlueViewController"bundle:nil]autorelease];

    [self.viewinsertSubview:self.blueViewController.viewatIndex:10];

}


- (IBAction)yellowClick:(id)sender {

    NSLog(@"yellow");

   //加上这句就可以红黄蓝任意点击

   [self.yellowViewController.viewremoveFromSuperview];

    self.yellowViewController = [[[BlueViewControlleralloc]initWithNibName:@"YellowViewController"bundle:nil]autorelease];

    [self.viewinsertSubview:self.yellowViewController.viewatIndex:10];

}

//主视图控制器

- (IBAction)redClick:(id)sender {

    NSLog(@"red");

    [self.yellowViewController.viewremoveFromSuperview];

    [self.blueViewController.viewremoveFromSuperview];

}


- (void)dealloc {

    [_txtName release];

    [_txtPassword release];

    [_yellowViewControllerrelease];

    [_blueViewController release];

    [super dealloc];

}

- (IBAction)returnBoard:(id)sender forEvent:(UIEvent *)event {

    [self.txtPasswordresignFirstResponder];

    [self.txtNameresignFirstResponder];

}

@end


BlueController.h:

#import <UIKit/UIKit.h>

@class DXWViewController;

@interface BlueViewController : UIViewController

@property (retainnonatomicIBOutlet UILabel *lblName;

@property (retainnonatomicIBOutlet UIImageView *img;

@property(retain,nonatomic)DXWViewController *dxwViewController;

- (IBAction)btnReturn:(id)sender;

@property (retainnonatomicIBOutlet UIImageView *img2;

@end


BlueController.m:

#import "BlueViewController.h"

#import "Number.h"

#import "DXWViewController.h"

@interface BlueViewController ()


@end


@implementation BlueViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [superviewDidLoad];

    

}


-(void)viewDidAppear:(BOOL)animated

{

    self.lblName.text = [NumbergetNumber].name;

    //[self.img setImage:[UIImage imageNamed:@"dog.jpg"]];

    if ([self.lblName.textisEqualToString:@"apple"]) {

        self.img.hidden =NO;

    }

    elseif([self.lblName.textisEqualToString:@"dog"]){

        self.img2.hidden =NO;

    }

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (void)dealloc {

    [_lblName release];

    [_img release];

    [_dxwViewController release];

    [_img2 release];

    [super dealloc];

}


- (IBAction)btnReturn:(id)sender {

    [UIView beginAnimations:@"anim"context:nil];

    //一个动画的持续时间

    [UIView setAnimationDuration:1.5f];

    //一个动画的运动随时间快慢曲线

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    //动画方式

    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES];

     

    //如果当前view的父view存在

    self.dxwViewController = [[[DXWViewControlleralloc]initWithNibName:@"DXWViewController"bundle:nil]autorelease];

    [self.viewinsertSubview:self.dxwViewController.viewatIndex:12];

    //动画效果启动

    [UIView commitAnimations];


}

@end


动态添加ImageView到view中:

UIImage *image = [UIImage imageNamed:@"apple.jpg"];

        UIImageView *picView = [[UIImageViewallocinitWithImage:image];

        [self.viewinsertSubview:picView atIndex:13];

        picView.frame = CGRectMake(49,62200160);


源文件:http://download.csdn.net/detail/s10141303/5946851
























本文转蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366563,如需转载请自行联系原作者

相关文章
|
7月前
|
定位技术 iOS开发
iphone4s经过地图页面直接跳转到其它页面导致页面不能正常加载
iphone4s经过地图页面直接跳转到其它页面导致页面不能正常加载
50 0
|
Android开发 iOS开发
Android 开关按钮切换,类似于iphone 效果,view实现
1、实现的效果            gitHub :  https://github.com/zcweng/ToggleButton
2268 0
|
iOS开发
iphone绘图的几个基本概念CGPoint、CGSize、CGRect、CGRectMake、window(窗口)、视图(view)
我一般情况下不会使用interface builder去画界面,而是用纯代码去创建界面,不是装B,而是刚从vi转到xcode不久,不太习惯interface builder而已。当然如果需要我也会使用它。
882 0
|
1月前
|
编解码 测试技术 iOS开发
iPhone 屏幕尺寸和开发适配
【10月更文挑战第23天】iPhone 的屏幕尺寸变化给开发者带来了一定的挑战,但也为创新提供了机遇。通过深入了解不同屏幕尺寸的特点,遵循适配原则和策略,运用合适的技巧和方法,我们能够为用户提供在不同 iPhone 机型上都具有良好体验的应用。在未来,随着技术的不断进步,我们还需要持续学习和适应,以满足用户对优质应用体验的不断追求。
|
1月前
|
编解码 iOS开发 UED
响应式设计在 iPhone 开发适配中的具体应用
【10月更文挑战第23天】响应式设计在 iPhone 开发适配中扮演着至关重要的角色,它能够帮助我们打造出适应不同屏幕尺寸和用户需求的高质量应用。通过合理运用响应式设计的原则和方法,我们可以在提供良好用户体验的同时,提高开发效率和应用的可维护性。
|
4月前
|
数据采集 iOS开发 Python
Chatgpt教你开发iPhone风格计算器,Python代码实现
Chatgpt教你开发iPhone风格计算器,Python代码实现
|
Shell iOS开发
iOS逆向:tweak开发教程(iPhone/tool)
iOS逆向:tweak开发教程(iPhone/tool)
1263 0
iOS逆向:tweak开发教程(iPhone/tool)
|
编解码 iOS开发
iphone 开发的基本入门知识
iphone 开发的基本入门知识
238 0