Created
August 8, 2014 20:53
-
-
Save jeremytregunna/142160146f4d912b2fd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notification name as a constant, keep things clean. You'll see why this is needed soon. | |
static NSString* const MyStopNotificationName = @"MyStopNotificationName"; | |
// Somewhere in your code you've got a button... | |
[self.someButton addTarget:self action:@selector(startConnection) forControlEvents:UIControlEventTouchUpInside]; | |
// Somewhere else you have this method implemented | |
- (void)startConnection | |
{ | |
self.someButton.enabled = NO; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopConnection) name:MyStopNotificationName object:nil]; | |
// It does the thing that is required to start your connection. Forget about setting connectionStarted, you don't need it. | |
} | |
- (void)stopConnection | |
{ | |
// This is called when that notification is posted, and only then. | |
self.someButton.enabled = YES; | |
} | |
// Whenever you would have set the connectionStopped boolean, do this instead: | |
[[NSNotificationCenter defaultCenter] postNotificationName:MyStopNotificationName object:nil]; | |
// Profit! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment