Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

iphone - How to get UIButton Target, Action and Control events?

I am using UIImageView's with UIButtons a whole bunch. So, I created a custom class to permanently marry these two an make things a little simpler. It all works well until I decided to implement -(id)initWithObject:(AUIImageViewButton *) imageViewButton.

Clearly I need to copy all relevant properties from the imageViewButton object being passed. The UIImageView is not problematic at all. Something like this deals with it:

imageview = [[UIImageView alloc] initWithFrame:imageViewButton.imageview.frame];        // Copy all relevant data from the source's imageview
[imagebutton.imageview setBackgroundColor:imageViewButton.imageview.backgroundColor];   //
[imagebutton.imageview setImage:imageViewButton.imageview.image];                       //

Most of the button stuff is also readily available:

button = [UIButton buttonWithType:imageViewButton.button.buttonType];                   // Copy all relevant data from the source's button
button.frame = imageViewButton.imageview.frame;                                         // 
[button setTitle:imageViewButton.button.titleLabel.text forState:UIControlStateNormal]; //
button.tag = imageViewButton.button.tag;                                                //

I am having a little trouble figuring out how to get all the data for the addTarget:action:forControlEvents method.

Looking at the docs I can see that I might be able to use UIControl's allControlEvents and allTargets methods. I'll dig into that right now and see how much trouble I can get into. The one I am not sure about is the action.

Can anyone give me a shove in the right direction?

Thanks,

-Martin

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UIControl's allTargets and allControlEvents are the way to start. The final piece of the puzzle is actionsForTarget:forControlEvent:, call it once for each target and event.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...