开发者

Where are events in Cocoa Touch?

开发者 https://www.devze.com 2022-12-27 02:14 出处:网络
I learn Cocoa Touch several days, and today have stuck while looking for way to imp开发者_StackOverflow中文版lement a custom event. Event that I can see in Connection Inspector for my UIView subclass.

I learn Cocoa Touch several days, and today have stuck while looking for way to imp开发者_StackOverflow中文版lement a custom event. Event that I can see in Connection Inspector for my UIView subclass.

What I have:

There are a UILabel and MyView:UIView on MainVindow. MyView contains a UISlider. Interfaces for Controller and MyView

// Controller.h 
@interface Controller : NSObject {
   IBOutlet UILabel *label;
   IBOutlet MyView *myView;
}
// I suppose that there should be something like -(IBAction) changeLabelValue for myView event
@end

// MyView.h
@interface MyView : UIView {
    IBOutlet UISlider *slider;
    float value;
}
- (IBAction) changeValue; //for slider "Changed Value" event

What I want:

Add something in MyView that allows it to rise a event after change value.

Can anybody help me? My main area in programming is .NET and I begin think that its terminology is not appropriate for this case.

Thanks.


I don’t know if I'm understanding you correctly but I think what you want is responding to user events from interface components. In Cocoa the term "event" is only used for objects that describe the actual event, like a touch down or key up.

To respond to higher level events, like dragging a slider or pushing a button, Cocoa uses the target action paradigm. You set up a UI component (a UIControl derived view class) to send a given message to a given target whenever the component detects a change of its state.

To set the target and the action method you can use Interface Builder or the UIControl method addTarget:action:forControlEvents:.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号