IOS中的target action控件的實(shí)現(xiàn)
IOS中的target action控件的實(shí)現(xiàn)
實(shí)現(xiàn)代碼:
#import <Foundation/Foundation.h> @interface Sample : NSObject { SEL action; id target; } @property SEL action; @property (assign) id target; -(void)addTarget:(id) t action:(SEL) s; -(void)sample_dosomthing; @end
#import "Sample.h" @implementation Sample @synthesize action; @synthesize target; -(void)dealloc{ target = nil; [super dealloc]; } -(void)addTarget:(id) t action:(SEL) s{ self.action = s; self.target = t; } -(void)sample_dosomthing{ [self.target performSelector:self.action]; } @end
這是一個例子,在一個UIViewController里面
-(void)control_dosomthing{ NSLog(@"control_dosomthing"); } - (void)viewDidLoad { [super viewDidLoad]; Sample *sample1 = [Sample new]; [sample1 addTarget:self action:@selector(control_dosomthing)]; }
以上就是IOS中的target action控件的實(shí)現(xiàn),如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
iOS界面跳轉(zhuǎn)時導(dǎo)航欄和tabBar的隱藏與顯示功能
這篇文章主要介紹了iOS界面跳轉(zhuǎn)時導(dǎo)航欄和tabBar的隱藏與顯示功能,需要的朋友可以參考下2017-02-02iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式
在本文里我們給大家分享了關(guān)于iOS開發(fā)Quick Actions創(chuàng)建桌面Icon快捷方式的相關(guān)知識點(diǎn)內(nèi)容,需要的讀者們可以參考下。2019-05-05iOS 報clang: error: no input files錯誤的解決方法
這篇文章主要給大家介紹了關(guān)于iOS報clang: error: no input files錯誤的解決方法,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01解決ios h5 input輸入框被輸入法彈出一塊區(qū)域的問題
今天小編就為大家分享一篇解決ios h5 input輸入框被輸入法彈出一塊區(qū)域的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08iOS實(shí)現(xiàn)底部彈出PopupWindow效果 iOS改變背景透明效果
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)底部彈出PopupWindow效果,iOS改變背景透明效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-07-07混合棧跳轉(zhuǎn)導(dǎo)致Flutter頁面事件卡死問題解決
這篇文章主要為大家介紹了混合棧跳轉(zhuǎn)導(dǎo)致Flutter頁面事件卡死問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08