passing data between views

后端 未结 3 1064
南方客
南方客 2020-12-11 10:20

So i\'m trying to pass data between two views (first view is tableViewController,when cell is pressed data is send to second view,second view got imageView, when data is sen

相关标签:
3条回答
  • 2020-12-11 10:45

    In any class where you want to set any variable of the "AppDelegate Class", you can try this, this will surely solve your problem.

     //Declare a variable from where you want to set the value of the "AppDelegate Class". 
     //in the yourclass.h file.
     AppDelegate/* this is the main class of the Application*/ *appDel;
    
    //and initialize it where you want to use or you can initialize at the init of the class.  
    
    appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    
     // Then set the value.
     appDel.imageString = tempImageString;
    
    0 讨论(0)
  • 2020-12-11 10:49

    In a class if you want to use a protocal you can use like as :

      // this the way too declare  a protocal.
      // .h file
     @protocol TestProtocol <NSObject>
    
     -(void)testMyProtocolMethod:(NSString *)testvalue;
    
     @end
    
    @interface TestProtocolClass: NSObject
    {
       id <TestProtocol> delegate;
    
    }
     @property (nonatomic , assign) id <TestProtocol> delegate;
     /* synthesize in the .m file   of          this      class*/
     @end
    
    
    
     //Now you have to use this protocol in any class where you want to use , Do like as:
     //let us suppose you want to use this protocal method in a class named "DemoProtocal".
     // .h file 
     import "TestProtocol.h"
     @interface DemoProtocal <TestProtocol>{
    
     }
     @end
    
    //.m file
     #import "DemoProtocal.h"
     @implementation DemoProtocal
    
    - (id)init{
    
      TestProtocol *test = [[TestProtocol alloc]init];
      test.delegate = self;
    
     }
    
    -(void)testMyProtocolMethod:(NSString *)testvalue{
    
      // Do appropriate things.
     }
     @end
    
    0 讨论(0)
  • 2020-12-11 11:03

    First Check theAppDataObject is null or not.

    If it is null then:

    Write AppDataObject* theDataObject; in your inteface and declare a property as strong

    If theDelegate.theAppDataObject is returning null , allocate that object first.

    If it is not null then:

    Change this line theAppDataObject.imageString = tempImageString;

    to

    theAppDataObject.imageString = [tempImageString retain];
    

    If you are using ARC set the property of imageString to strong.

    or Check with this

    theAppDataObject.imageString = [[NSString alloc] initWthString:tempImageString];

    0 讨论(0)
提交回复
热议问题