passing data between views

后端 未结 3 1066
南方客
南方客 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: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 
    
     -(void)testMyProtocolMethod:(NSString *)testvalue;
    
     @end
    
    @interface TestProtocolClass: NSObject
    {
       id  delegate;
    
    }
     @property (nonatomic , assign) id  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 {
    
     }
     @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
    

提交回复
热议问题