• 属性传值


    #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
  • 相关阅读:
    【二分图匹配/匈牙利算法】飞行员配对方案问题
    【模板/学习】匈牙利算法
    【tarjan缩点+分层图】草鉴定Grass Cownoisseur
    【微笑】
    【质因数分解】SAC E#1 一道中档题 Factorial
    【dfs+dp】砝码称重
    【背包dp】自然数拆分Lunatic版
    【单调队列】最大子序和
    【单调队列】滑动窗口
    bzoj 2834: 回家的路
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5421243.html
Copyright © 2020-2023  润新知