单例传值 南哥教的


//pch文件里面写出宏  这是系统的单例类  当然也是可以自己去写一个单例类的


#define APPDELEGATE UIApplication * app = [UIApplication sharedApplication];AppDelegate * appdelegate = (AppDelegate *)app.delegate;



刚开始写在cellforRow函数里面  这个函数是进不来的  所有另外一个界面虽然打印是有值的   但是没传过来的


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    

    //    for (UIView *view in cell.subviews) {

    //        [view removeFromSuperview];

    //    }

    //

    

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    cell.textLabel.text = [[dataArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

    

    

    if (indexPath.section==0) {

        if (indexPath.row==1) {

            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;


           lab00=[[UILabel alloc] initWithFrame:CGRectMake(200, 0, 120, 48)];

            lab00.backgroundColor=clear;

//            lab.text=[arr objectAtIndex:indexPath.row-1];

            

//            MySingletonClass *sing=[MySingletonClass mySharedApplication];  自己写的单例类

//            lab.text=sing.huiFui;

            

//            lab.text=@"fdshjjkfds";

//            

//            APPDELEGATE;  //这个是由宏定义得来的  系统的单例类   

//            lab00.text=appdelegate.chuanzhi;

            

//                NSLog(@"%@",appdelegate.chuanzhi);、//此时这个函数里面打印出来是没有值的

            

            

            lab00.textColor=Black1;

            lab00.font=FONT_13;

            lab00.textAlignment=NSTextAlignmentLeft;

            [cell addSubview:lab00];

            [lab00 release];

            

            

            

            

        }








此时应该  把lab00  写成是全局的    刚进入界面的时候  总会调用这几个函数的   viewwillappear   也是可以的


-(void)viewDidAppear:(BOOL)animated

{

    APPDELEGATE;

    if(appdelegate.chuanzhi != nil){

        lab00.text = appdelegate.chuanzhi;  相当于代理中的回调  

    }

}




//楠哥教的。。。。。。


  

        



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值