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];




  • 相关阅读:
    godaddy的win主机发邮件的组件
    读取excel的时候,往往多了很多空白行,下面的代码是去掉空白行的
    where泛型约束
    博客园页面有问题,
    今晚就出发回家啦!!!!
    呵呵,日期小小技巧
    获取设置本地当前默认打印机
    Queue Explorer过期处理
    SQL多关键字查询 并按精确度排序
    python 高阶函数
  • 原文地址:https://www.cnblogs.com/allanliu/p/4173229.html
Copyright © 2011-2022 走看看