How to pass a variable to a UIButton action

前端 未结 8 1551
南笙
南笙 2020-12-13 21:05

I want to pass a variable to a UIButton action, for example

NSString *string=@\"one\";
[downbutton addTarget:self action:@selector(action1:string)
     forCo         


        
8条回答
  •  青春惊慌失措
    2020-12-13 21:34

    You can extends UIButton and add a custom property

    //UIButtonDictionary.h
    #import 
    
    @interface UIButtonDictionary : UIButton
    
    @property(nonatomic, strong) NSMutableDictionary* attributes;
    
    @end
    
    //UIButtonDictionary.m
    #import "UIButtonDictionary.h"
    
    @implementation UIButtonDictionary
    @synthesize attributes;
    
    @end
    

提交回复
热议问题