How do I create delegates in Objective-C?

后端 未结 19 2516
一整个雨季
一整个雨季 2020-11-21 04:48

I know how delegates work, and I know how I can use them.

But how do I create them?

19条回答
  •  我在风中等你
    2020-11-21 05:22

    //1.
    //Custom delegate 
    @protocol TB_RemovedUserCellTag 
    
    -(void)didRemoveCellWithTag:(NSInteger)tag;
    
    @end
    
    //2.
    //Create a weak reference in a class where you declared the delegate
    @property(weak,nonatomic)id  removedCellTagDelegate;
    
    //3. 
    // use it in the class
      [self.removedCellTagDelegate didRemoveCellWithTag:self.tag];
    
    //4. import the header file in the class where you want to conform to the protocol
    @interface MyClassUsesDelegate ()
    
    @end
    

    //5. Implement the method in the class .m -(void)didRemoveCellWithTag:(NSInteger)tag { NSLog@("Tag %d",tag);

    }

提交回复
热议问题