views:

28

answers:

2

Hello, newbie here. This is an iPhone utility project.

First things first. I have a protocol that is this:

@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
- (void)updateLabels:(NSString *)text :(BOOL)isOn;
@end

I implement this protocol in my MainViewController by doing this:

- (void)updateLabels:(NSString *)text :(BOOL)isOn {
    [nameLabel setText:text]; 
     if (isOn)
      [onLabel setText:(@"ON")];
     else
      [onLabel setText:(@"OFF")];
     }

Now I'm wanting to use the updateLabels method in my FlipsideViewController in a method called buttonClick. How would I refer to the updateLabels method located in MainViewController?

+2  A: 

[self updateLabels:@"foo" :YES];

By the way, while it's possible to do an unnamed parameter to a method (like you have), it's generally considered bad practice without a very good reason otherwise. :)

Dave DeLong
Thank you for your info.
willingfamily
+1 for the style reminder.
Alex Martini
A: 

Based on your EDIT above, I think you might be confused about delegate protocols.

Delegation is where you have a second object, the delegate, that adopts the delegate protocol. Then the FlipsideViewController object calls methods (which are part of that protocol) on the delegate object. What this means is that FlipsideViewController shouldn't implement the FlipsideViewControllerDelegate protocol, and so you shouldn't be calling methods from that protocol on it.

Here's some more information on delegation: http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Delegation.html%23//apple_ref/doc/uid/TP40008195-CH14-SW1

And some more on protocols: http://developer.apple.com/library/mac/#documentation/General/Conceptual/DevPedia-CocoaCore/Protocol.html%23//apple_ref/doc/uid/TP40008195-CH45-SW1

Alex Martini
Thanks for the info, I'll give those a good read.
willingfamily
Edit: To those who find this question again, I found a way to do this. You just need to do `self.delegate updateLabels:@"foo" "YES];`
willingfamily