delegates

C# pattern to prevent an event handler hooked twice [duplicate]

你。 提交于 2019-12-17 05:33:33
问题 This question already has answers here : How to ensure an event is only subscribed to once (5 answers) Closed 4 years ago . Duplicate of: How to ensure an event is only subscribed to once and Has an event handler already been added? I have a singleton that provides some service and my classes hook into some events on it, sometimes a class is hooking twice to the event and then gets called twice. I'm looking for a classical way to prevent this from happening. somehow I need to check if I've

iBeacon: didRangeBeacons stops getting called, must reset device for it to work again

梦想的初衷 提交于 2019-12-17 04:07:50
问题 I am using a custom BeaconManager delegate so that beacon ranging is not determined by the life-cycle of the view controller. Everything works great but every once in a while (1-2 days) beacon ranging will stop working and didRangeBeacons will never get called. The only way to fix this is for me to reset my iPhone, once I do this, it works perfectly. Below is the code that I am using. The basic flow is that when my ViewController calls ViewDidLoad it sends a notification back to the

iBeacon: didRangeBeacons stops getting called, must reset device for it to work again

一笑奈何 提交于 2019-12-17 04:07:01
问题 I am using a custom BeaconManager delegate so that beacon ranging is not determined by the life-cycle of the view controller. Everything works great but every once in a while (1-2 days) beacon ranging will stop working and didRangeBeacons will never get called. The only way to fix this is for me to reset my iPhone, once I do this, it works perfectly. Below is the code that I am using. The basic flow is that when my ViewController calls ViewDidLoad it sends a notification back to the

Performance of calling delegates vs methods

狂风中的少年 提交于 2019-12-17 03:02:53
问题 Following this question - Pass Method as Parameter using C# and some of my personal experience I'd like to know a little more about the performance of calling a delegate vs just calling a method in C#. Although delegates are extremely convenient, I had an app that did lots of callbacks via delegates and when we rewrote this to use callback interfaces we got an order of magnitude speed improvement. This was with .NET 2.0 so I'm not sure how things have changed with 3 and 4. How are calls to

Performance of calling delegates vs methods

流过昼夜 提交于 2019-12-17 03:02:12
问题 Following this question - Pass Method as Parameter using C# and some of my personal experience I'd like to know a little more about the performance of calling a delegate vs just calling a method in C#. Although delegates are extremely convenient, I had an app that did lots of callbacks via delegates and when we rewrote this to use callback interfaces we got an order of magnitude speed improvement. This was with .NET 2.0 so I'm not sure how things have changed with 3 and 4. How are calls to

Why must a lambda expression be cast when supplied as a plain Delegate parameter

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 02:42:16
问题 Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: string str = "woop"; Invoke(() => this.Text = str); // Error: Cannot convert lambda expression to type 'System.Delegate' // because it is not a delegate type Yet this works fine: string str = "woop"; Invoke((Action)(() => this.Text = str)); When the method expects a plain Delegate? 回答1: A lambda expression can either be converted to a delegate type or an expression tree - but it has

When & why to use delegates? [duplicate]

时光怂恿深爱的人放手 提交于 2019-12-17 02:00:34
问题 This question already has answers here : Where do I use delegates? [closed] (8 answers) Closed 6 years ago . I'm relatively new in C#, & I'm wondering when to use Delegates appropriately . they are widely used in events declaration, but when should I use them in my own code and why are they useful? why not to use something else? I'm also wondering when I have to use delegates and I have no other alternative . Thank you for the help! EDIT: I think I've found a necessary use of Delegates here

What's the best way to communicate between view controllers?

ⅰ亾dé卋堺 提交于 2019-12-16 20:03:20
问题 Being new to objective-c, cocoa, and iPhone dev in general, I have a strong desire to get the most out of the language and the frameworks. One of the resources I'm using is Stanford's CS193P class notes that they have left on the web. It includes lecture notes, assignments and sample code, and since the course was given by Apple dev's, I definitely consider it to be "from the horse's mouth". Class Website: http://www.stanford.edu/class/cs193p/cgi-bin/index.php Lecture 08 is related to an

Subclass a zooming UIScrollView without delegate methods

谁都会走 提交于 2019-12-14 01:01:26
问题 I want to implement a UIScrollView subclass to present some custom formatted content. I just set a model object property of the scroll view and it handles all the required layout and rendering to display the content. This works fine, but now I'd like to include zooming. According to the documentation, to support zooming you have to set a delegate and implement the viewForZoomingInScrollView: method. I guess I could set the delegate to the scroll view itself and implement that method in the

Objective C callbacks with blocks

佐手、 提交于 2019-12-13 23:41:22
问题 I have looked at various answers on SO for this but can't quite get my head around how it all actually works. What I have is a GameEngine that contains touchable elements, what I want is for when an element is touched it fires off a "I have been touched" event that the GameEngine listens for and deals with appropriately. In C# I'd do this with delegates/events but can't seem to find a decent obj c equivalent that uses blocks. - I want to use Blocks as it more akin to anonymous functions in C#