YIem`s Blog -心比天高命比纸薄-链接找不到的请在站内搜索内容!

2015-12-16--UI7_页面跳转 - 传值

//
// AppDelegate.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (retain, nonatomic) UIWindow *window;

@end


//
// AppDelegate.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "AppDelegate.h"

import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

@end



//
// RootViewController.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end


//
// RootViewController.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "RootViewController.h"

import "SecondViewController.h"

@interface RootViewController ()
@property (nonatomic, retain)UITextField *textField;
@end

@implementation RootViewController

// seg.frame = CGRectMake(100, 100, 100, 30);
// seg.selectedSegmentIndex = 0;
// self.navigationItem.titleView = seg;
// [seg release];

// 标题
self.title = @"首页";







// textField

_textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];

_textField.backgroundColor = [UIColor redColor];
_textField.placeholder = @"sda";
[self.view addSubview:_textField];
[_textField release];


//    按钮
UIButton *bt = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 50, 30)];
bt.backgroundColor = [UIColor yellowColor];

[bt addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bt];
[bt release];







}
-(void)button
{

NSLog(@"diandian");

// push页面
// 1.创建第二页对象
SecondViewController *secVC = [[SecondViewController alloc]init];

warning 2. 给第二页面的对象属性赋值

secVC.str = self.textField.text;

// 2.push操作 导航控制页面的push
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];

if 0



// 模态
// 1.创建对象
SecondViewController *secVC = [[SecondViewController alloc]init];
// 2.模态
[self presentViewController:secVC animated:YES completion:^{
    //
}];

endif

}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

*/

@end



//
// SecondViewController.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

warning 界面之间通信 属性传值(1->2)

warning 1.在第二页的.h文件 写一个对应类型的属性 用于接收数据

@property (nonatomic, copy)NSString *str;
@end


//
// SecondViewController.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//

import "SecondViewController.h"

import "RootViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

warning 3.使用属性

// 设置标题
self.title = self.str;




//创建按钮
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[button release];


}

}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

*/

@end

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »