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


相关文章
|
9月前
|
弹性计算 运维 监控
OS Copilot-操作系统智能助手测试报告-新人体验
测试体验OS copilo安装、启动,体验copilot的提供的`-t`、`-f`、`|`通道的指令在在精准分析、批量任务处理、文件分析的能力。并记录下来。
287 18
计算机网络——物理层-信道的极限容量(奈奎斯特公式、香农公式)
计算机网络——物理层-信道的极限容量(奈奎斯特公式、香农公式)
618 0
|
存储 搜索推荐
Rstudio常用快捷键以及窗口操作有用技巧
Rstudio常用快捷键以及窗口操作有用技巧
718 0
|
敏捷开发 负载均衡 监控
微服务架构下的服务发现机制
【4月更文挑战第22天】 在现代软件工程中,微服务架构已成为构建可扩展和灵活后端系统的重要方式。随着服务的增多和动态性增强,如何有效进行服务发现成为了保障系统高可用性和敏捷性的关键。本文将深入探讨微服务环境中的服务发现模式,分析其必要性,并比较各类服务发现机制的优劣及其适用场景。我们将重点讨论基于中心化注册和去中心化方法的实现原理,以及它们在实际项目中的挑战与解决方案。
150 1
|
关系型数据库 MySQL Linux
lamp架构
LAMP是流行的开源Web框架,包括Linux操作系统、Apache服务器、MySQL数据库和PHP编程语言。由于其通用性、跨平台、高性能和低成本,常用于企业网站搭建。本文档描述了在Redhat 9.0上通过yum安装配置LAMP的过程,包括安装Apache、MySQL(这里用的是mariadb)、PHP,并通过WordPress测试环境。安装步骤涉及启动服务、设置开机自启、修改MySQL安全设置、安装PHP组件以及创建PHP测试文件和WordPress站点。最后,文档展示了成功访问WordPress管理页面的截图。
242 3
|
Java 数据库 数据安全/隐私保护
用shiro框架实现注册登陆,让你快速理解shiro用法
用shiro框架实现注册登陆,让你快速理解shiro用法
583 0
用shiro框架实现注册登陆,让你快速理解shiro用法
|
SQL Java 数据库连接
JAVAEE框架技术之15SSM综合案例 订单管理查询
JAVAEE框架技术之15SSM综合案例 订单管理查询
170 0
JAVAEE框架技术之15SSM综合案例 订单管理查询
|
安全
数据结构进阶 AVL树
数据结构进阶 AVL树
138 0
数据结构进阶 AVL树
|
机器学习/深度学习 人工智能
《阿里云产品手册2022-2023 版》——AI与机器学习
《阿里云产品手册2022-2023 版》——AI与机器学习
437 0