单例传值 南哥教的

来源:互联网 发布:手机数据上网慢怎么办 编辑:程序博客网 时间:2024/06/12 23:05


//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 = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

    }

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

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

    

    

   if (indexPath.section==0) {

       if (indexPath.row==1) {

            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;


          lab00=[[UILabelalloc] 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;

            [celladdSubview:lab00];

            [lab00release];

            

            

            

            

        }








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


-(void)viewDidAppear:(BOOL)animated

{

    APPDELEGATE;

   if(appdelegate.chuanzhi !=nil){

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

    }

}




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


  

        



原创粉丝点击