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

简介: 在第一个界面登陆,在第二个界面显示名字,并且根据不同的名字显示不同的图片 (最好不要加toolbar) 效果图: 单例Number.h: #import @interface Number : NSObject {     NSStrin...

在第一个界面登陆,在第二个界面显示名字,并且根据不同的名字显示不同的图片 (最好不要加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 (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


相关文章
|
移动开发 小程序 Android开发
小程序webview组件嵌H5页面,安卓手机没有问题,苹果有部分页面不显示
小程序webview组件嵌H5页面,安卓手机没有问题,苹果有部分页面不显示
192 0
|
6月前
|
UED
禁止手机侧滑返回上一个页面的三种方法
禁止手机侧滑返回上一个页面的三种方法
383 0
|
iOS开发
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
277 0
iOS开发 - touchBegan事件判断点击的位置在View上还是在View的子View上
|
Java Android开发 前端开发
判断客户端手机类型,并跳转到相应的app下载页面
实现的原理,是检测浏览器的 USER-AGENT 这个header,然后根据正则表达式来确定客户端类型。  如果都不匹配,Fallback回退策略是显示对应的页面,让用户自己选择。 适合采用二维码扫描方式下载APP: JSP版本的代码如下所示:其他服务端版本请百度搜索。
901 0
|
前端开发 Go
React Native之通过createStackNavigator实现携带参数的页面与页面之间的跳转
React Native之通过createStackNavigator实现携带参数的页面与页面之间的跳转
194 0
React Native之通过createStackNavigator实现携带参数的页面与页面之间的跳转
|
XML Android开发 iOS开发
Android开发之Activity的创建跳转及传值
在Android系统的江湖中有四大组件:活动(Activity), 服务(Service), 广播接收器(Broadcast Reciver)和内容提供者(Content Provider)。
1158 0