zoukankan      html  css  js  c++  java
  • ios页面传值的几种方法


    1.属性
    2.方法
    3.代理方法
    4.SharedApplication
    5.NSUserdefault
    6.通过一个单例的class来传递

    属性这种方法传值挺方便的,只需要拿到它的指针,如果重新声明一个指针,就不是原来的内容,不是同一个指针,因此需要传指针。

    xxxViewController *document = [[xxxViewController alloc] initWithStyle:UITableViewStyleGrouped];
    document.docDict = [self.dataArray objectAtIndex:indexPath.row];
    document.properties = 要传的值
    [self.navigationController pushViewController:document animated:YES];
    [document release];


    方法传值这个只要声明要传到那个类的实例变量和方法,就把当前的页面的值传过去。

    代理适合从后向前传值。详细参考。

    NSUserdefault这个是一个字典,经常用来存储用户名和密码。但是传多次时候有可能覆盖前面的内容。

    SharedApplication相当与一个全局变量 [UIApplication UISharedApplication].delegete这个方法还没用过

    单例这个也相当与全局的变量

    [[UIApplication sharedApplication] delegate];
    你可以在AppDelegate里写一个宏:
     

    #define APP_DELEGATE        ((AppDelegate *)[[UIApplication sharedApplication] delegate])


    后面就能用
       

    #import "AppDelegate.h"
    [APP_DELEGATE.window addSubview:xxxxxx];
     
    FmovieAppDelegate* appDelegate = (FmovieAppDelegate*)[[UIApplication sharedApplication] delegate];
     
    [self.navigationController pushViewController:appDelegate.cinemaViewController animated:YES];




  • 相关阅读:
    Oracle/Mysql批量插入的sql,效率比较高
    wget 无法下载jdk的处理办法
    C# 模拟提交带附件(input type=file)的表单
    WCF跟踪分析 使用(SvcTraceViewer)
    mysql 添加用户并授权(记录)
    SQLSERVER 跨服务器查询
    Hive
    《JAVA与模式》之建造模式
    《JAVA与模式》之单例模式
    Hadoop的HA机制
  • 原文地址:https://www.cnblogs.com/allanliu/p/4173229.html
Copyright © 2011-2022 走看看