zoukankan      html  css  js  c++  java
  • [某鸥实训记][objective-c][第二天][个人笔记]

    今天学到了几种传值方式...直接粘在课上做的笔记了

    • 不知道叫什么的用变量来传值
       FirstViewController *firstVC = [[FirstViewController alloc] init];
    
        firstVC.str = _textField.text;
    
        [self.navigationController pushViewController:firstVC animated:YES];
    
    • 单例传值
    //SingleTon.m
    
    static SingleTon *ton = nil;
    
    + (SingleTon *)shareTon{
      if (ton == nil) {
            ton = [[SingleTon alloc] init];
        }
        return ton;
    }
    
     
    
    //写值
    
        SingleTon *ton = [SingleTon shareTon];
        ton.str = _textField.text;
    
     
    
    //读值
    
      SingleTon *ton = [SingleTon shareTon];
      _label.text = ton.str;
    • 通知传值
    //创建通知 通知的名字为name,发送的内容是一个字典类型
    
    NSNotification *note = [[NSNotification alloc] initWithName:@"name" object:self userInfo:[NSDictionary dictionaryWithObject: _textField.text forKey:@"key"]];
    
    //发送通知
    [[NSNotificationCenter defaultCenter] postNotification:note];
    
    //接收通知 接收通知,执行(note:)函数 通知的名字为name
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(note:) name:@"name" object:nil];
    
    //处理通知
    -(void)note:(NSNotification *)note{
        NSLog(@"%@",[note.userInfo objectForKey:@"key"]);
    }
    
  • 相关阅读:
    第八章 用通配符进行过滤
    第七章 数据过滤
    第六章 过滤数据
    第五章 排序和检索数据
    第四章 检索数据
    MySql 首记
    Effective C++ 6.继承与面向对象设计
    Effective C++ 5.实现
    ~~函数基础(五):内置函数~~
    ~~函数基础(四):递归函数~~
  • 原文地址:https://www.cnblogs.com/NyaSu/p/4798807.html
Copyright © 2011-2022 走看看