zoukankan      html  css  js  c++  java
  • 属性传值

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        //初始化导航控制器
        UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];
        self.window.rootViewController = navi;
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end
    #import "RootViewController.h"
    #import "LFViewController.h"
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //添加按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(100, 100, 150, 60);
        [button setTitle:@"跳到下一个页面" forState:0];
        [button setBackgroundColor:[UIColor greenColor]];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    
    /**
     *  按钮事件
     */
    - (void)buttonAction:(UIButton*)sender{
        /**
         *  属性传值,从一个控制器push到下一个控制器使用属性传值比较方便
         */
        LFViewController *lfController = [[LFViewController alloc] init];
        //把值传给LFViewController中的CityName
        lfController.cityName = @"北京";
        [self.navigationController pushViewController:lfController animated:YES];
    }
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface LFViewController : UIViewController
    
    @property(nonatomic , strong) NSString *cityName;//设置属性
    
    @end
    #import "LFViewController.h"
    
    @interface LFViewController ()
    
    @end
    
    @implementation LFViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //打印cityName的值
        NSLog(@"cityName:%@",self.cityName);
        UILabel *cityNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 150, 60)];
        cityNameLabel.backgroundColor = [UIColor redColor];
        //显示城市的名字
        cityNameLabel.text = self.cityName;
        cityNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:cityNameLabel];
    }
    
    @end
  • 相关阅读:
    Zookeeper 集群安装
    Jexus部署.Net Core项目
    NetCore1.1+Linux部署初体验
    Linux初学
    高可用Redis服务架构分析与搭建
    前端开发JS白板编程题目若干
    Javascript中的Microtask和Macrotask——从一道很少有人能答对的题目说起
    ES6原生Promise的所有方法介绍(附一道应用场景题目)
    HTML的iframe标签妙用
    漫谈PHP代码规范
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5421243.html
Copyright © 2011-2022 走看看