target-action

Member reference base type 'Class' is not a structure or union - has the Fixit led me in the right direction?

心已入冬 提交于 2020-01-17 08:30:11
问题 I’m trying to make a delegate that will send messages from UIButtons within a custom UIView called SGView and am a bit out of my depth following the error messages. I recently learned how to get a delegate to send messages successfully from within an instance method. SGView includes a class method that arranges multiple UIButtons in a circle and was designed to be used by different UIViews. The geometry works when the method is called from a parent UIView. I have now declared the delegate by

iOS 消息的传递机制

烂漫一生 提交于 2020-01-07 13:14:57
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 转载原地址:http://beyondvincent.com/blog/2013/12/14/124-communication-patterns/ 注1:本文由破船译自 Communication Patterns 。 本文目录如下所示: 可用的机制 做出正确的选择 Framework示例 小结 每个应用程序或多或少,都由一些松耦合的对象构成,这些对象彼此之间要想很好的完成任务,就需要进行消息传递。本文将介绍所有可用的消息传递机制,并通过示例来介绍这些机制在苹果的Framework中如何使用,同时,还介绍了一些最佳实践建议,告诉你什么时机该选择使用什么机制。 虽然这一期的主题是关于Foundation Framework的,不过本文中还介绍了一些超出Foundation Framework(KVO和Notification)范围的一些消息传递机制,另外还介绍了delegation,block和target-action。 大多数情况下,消息传递该使用什么机制,是很明确的了,当然了,在某些情况下该使用什么机制并没有明确的答案,需要你亲自去尝试一下。 本文中,会经常提及接收者[recipient]和发送者[sender]。在消息传递机制中具体是什么意思,我们可以通过一个示例来解释:一个table view是发送者

How do I set the sender on a NSMenuItem's action?

时间秒杀一切 提交于 2019-12-20 10:01:28
问题 The Apple documentation says that the sender passed to the NSMenuItem's action can be set to some custom object, but I can't seem to figure out how to do this. Is there a method I'm not seeing someplace in the documentation? 回答1: I'm not sure what piece of documentation you're referring to (a link would help). You can use the -setRepresentedObject: method of NSMenuItem to associate an arbitrary object with a menu item: //assume "item" is an NSMenuItem object: NSString* someObj = @"Some

remove “one” action from multi actions in target-action UIbutton

不想你离开。 提交于 2019-12-14 03:01:17
问题 [_btt1 addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside]; [_btt1 addTarget:self action:@selector(clicked2:) forControlEvents:UIControlEventTouchUpInside]; There are 2 actions in _btt1. 2013-05-31 10:33:31.300 testTargetAndSelector[6029:c07] actions : ( "clicked:", "clicked2:" ) I remove clicked2 action like this. [_btt1 removeTarget:self action:@selector(clicked2:) forControlEvents:UIControlEventTouchUpInside]; but there is no action in _btt1. 2013-05-31

RemoveTarget from UITapGestureRecognizer

扶醉桌前 提交于 2019-12-13 14:04:14
问题 I've added an action as anonymous method to my gesture recognizer UITapGestureRecognizer tapGesture = new UITapGestureRecognizer (); tapGesture.AddTarget (() => HandleTap (tapGesture)); How can I remove the target? UIGestureRecognizer.Token is needed. 回答1: RTFM is true here: An instance of this class is returned when you invoke the UIGestureRecognizer's UIGestureRecognizer.AddTarget method. The AddTarget returns this token as a mechanism for later unsubscribing this particular action from the

Mouse events handlers

北城以北 提交于 2019-12-12 02:38:16
问题 MyNSImageView is a subclass of NSImageView, here I have: @interface MyNSImageView : NSImageView { } @end @implementation MyNSImageView //- (void) mouseDown: (NSEvent *) theEvent //{ // do not wish to implement mouseDown event handler from here //} @end In another class called MainView, I have: @interface MainView : NSView { MyNSImageView *ImageView1; MyNSImageView *ImageView2; } @end - (void)awakeFromNib { ImageView1 = [[[MyNSImageView alloc] initWithFrame:NSMakeRect(5, 5, 240, 240)]

How can I send a “UIControlEventValueChanged” event from my custom control?

会有一股神秘感。 提交于 2019-12-03 14:37:32
问题 I've created a custom picker view type of control by subclassing UIView. I would like to be able to send a "UIControlEventValueChanged" control event from within this control, so that I can register for it in whichever view controller is using the control. How can I can I get my custom control to trigger this event when I deem it should be triggered? 回答1: Assuming your custom control extends UIControl , then you simply do: [self sendActionsForControlEvents:UIControlEventValueChanged]; This

How can I send a “UIControlEventValueChanged” event from my custom control?

拥有回忆 提交于 2019-12-03 04:21:33
I've created a custom picker view type of control by subclassing UIView. I would like to be able to send a "UIControlEventValueChanged" control event from within this control, so that I can register for it in whichever view controller is using the control. How can I can I get my custom control to trigger this event when I deem it should be triggered? Assuming your custom control extends UIControl , then you simply do: [self sendActionsForControlEvents:UIControlEventValueChanged]; This will call all registered targets (via addTarget:action:forControlEvents: that this event has happened. 来源:

How do I set the sender on a NSMenuItem's action?

时光毁灭记忆、已成空白 提交于 2019-12-02 22:20:39
The Apple documentation says that the sender passed to the NSMenuItem's action can be set to some custom object, but I can't seem to figure out how to do this. Is there a method I'm not seeing someplace in the documentation? I'm not sure what piece of documentation you're referring to (a link would help). You can use the -setRepresentedObject: method of NSMenuItem to associate an arbitrary object with a menu item: //assume "item" is an NSMenuItem object: NSString* someObj = @"Some Arbitrary Object"; [item setRepresentedObject:someObj]; [item setAction:@selector(doSomething:)]; Then when the

Disable action - user taps on tabbar item to go to root view controller

六月ゝ 毕业季﹏ 提交于 2019-11-29 03:08:55
I want to disable the default action when user taps the tabbar item. For example, i have a tabbar with Tab1, Tab2 and Tab3. In Tab1, user can navigate from View1 to View3 (View1 > View2 > View3). If user is at View3, and he taps the Tab1, the application takes the user to View1 (the root view controller). I want to disable this functionality. I don't want the tap on Tab1 to pop all the view controllers. How can i do that? Edit: This behavior is a little strange, but a handy shortcut in case of deep hierarchy! You can implement following UITabBarControllerDelegate methods to disable this system