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

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

效果图:

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

单例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 (retain, nonatomic) IBOutlet UITextField *txtName;

@property (retain, nonatomic) IBOutlet 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 (retain, nonatomic) IBOutlet UILabel *lblName;

@property (retain, nonatomic) IBOutlet UIImageView *img;

@property(retain,nonatomic)DXWViewController *dxwViewController;

- (IBAction)btnReturn:(id)sender;

@property (retain, nonatomic) IBOutlet 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 = [[UIImageViewalloc] initWithImage:image];

        [self.viewinsertSubview:picView atIndex:13];

        picView.frame = CGRectMake(49,62, 200, 160);


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


上一篇:阿里云物联网平台云端NodeJS SDK使用简介


下一篇:用友超客企业空间新版上线 社交化业务属性更明显