If I followed your code properly, you do not need to adopt the mentioned protocol in your ChooseServerViewController
, only PreferencesViewController
.
The reasoning is you want to send data back to the previous view controller. Try:
@protocol defaultLocationChoice <NSObject>
- (void) locChoice:(NSString*)choice;
@end
Have your PreferencesViewController
implement that method so it receives the selection. You will have to store that in an appropriate instance variable.
// in PreferencesViewController.m
-(void)locChoice:(NSString*)choice {
self.choice = choice; // this just my example
}
When the choice is made (in ChooseServerViewController
) to send the choice back, call:
// this is in 'ChooseServerViewController.m' some where appropriate
[self.delegate locChoice:cellValue];
Your implementation is simply doing nothing with cell value (not even storing it, just logging it). When you return to PreferencesViewController
, you will now have the selected value and that view controller can what it wants with it.
Protocols are somewhat analgous to interfaces in Java or C#, but more flexible.
UPDATE:
The declaration for ChooseServerViewController
should look like:
#import "FileWithProtocolDecalration.h"
@interface ChooseServerViewController
.
.
.
@property ( nonatomic,assign) id<defaultLocationChoice> delegate;
.
.
.
@end