Calling delegate methods and calling selectors

Posted by Crystal on Stack Overflow See other posts from Stack Overflow or by Crystal
Published on 2012-03-28T23:22:16Z Indexed on 2012/03/28 23:28 UTC
Read the original article Hit count: 251

Filed under:

I'm new to the concept of delegates and selectors when used with notifications. So my first question is,

1) Let's say you have a button that has a delegate that implements some doWork method. If you want the same functionality that's in the method, is it 'ok' to just call that method? I didn't know if that was considered good coding practices and/or if you should do that, or do something different in getting that type of functionality. Like if that is ok architecture?

2) Similarly, with NSNotificationCenter, I see some code that posts a notification. Then there's a HandleSegmentedControl:(NSNotification *)notification method. If I want to manually have that functionality, but without pressing the segment control, is it 'ok' to just take that functionality out of that method and put it in a new method so it would look like this:

Original:

- (void)HandleSegmentedControl:(NSNotification *)notification {
    NSDictionary *dict = [userInfo notification];
    // do stuff with the dictionary
}

New:

- (void)HandleSegmentedControl:(NSNotification *)notification {
     NSDictionary *dict = [userInfo notification];
     [self newMethod:dict];
}

- (void)newMethod:(NSDictionary *)dict {
    // do stuff with the dictionary
}

- (void)myOtherMethodThatNeedsTheSameFunctionality {
     NSDictionary *dict = // create some dictionary
     [self newMethod:dict];
}

Sorry if these are basic questions. I'm not sure what the best practices are for things like this and wanted to start the right way. Thanks.

© Stack Overflow or respective owner

Related posts about iphone