I'm having some problems passing variables between viewcontrollers.., I've got two viewcontrollers, one pops up to adjust settings/parameters for searching, so it needs to pass some values to it's parent viewcontroller. But I can't seem to get the variable out of the local ViewController at all..
I've currently got a 'ZoekenVarDelegate' class setup to hold the delegation of the value (it's not the main app delegate, but that gave the same result, so to clean it up I decided to move it to it's own class):
ZoekenVarDelegate.h
ZoekenVarDelegate.m
Now the first controller that pops up is the 'ZoekenViewController', this has a searchbox with standard values, there's an options button that will popup a 'CategorieSelectorViewController' with PresentModalViewController, in this screen I want to populate some variables that I pass back to the 'ZoekenViewController'
I added a NSString that needs to be populated from 'CategorieSelectorViewController' to the 'ZoekenViewController':
And in the CategorieSelectorViewController I try to populate it (without success) like:
(part of) CategorieSelectorViewController.h
(part of) CategorieSelectorViewController.m
This is the main part that should happen, a user picks a value from a UIPickerView that is populated through an array and give back a value if it matches, the self.categorieID is properly set (debugger shows), but upon calling self.delegateRef.zoekenViewController.categoriezoekID = self.categorieID; it does nothing, it doesn't seem to populate a variable whatsoever or throw errors..
What am I missing here ?
I've currently got a 'ZoekenVarDelegate' class setup to hold the delegation of the value (it's not the main app delegate, but that gave the same result, so to clean it up I decided to move it to it's own class):
ZoekenVarDelegate.h
Code:
#import <UIKit/UIKit.h>
#import "CategorieSelectorViewController.h"
#import "ZoekenViewController.h"
@class CategorieSelectorViewController;
@class ZoekenViewController;
@interface ZoekenVarDelegate : NSObject <UIApplicationDelegate> {
ZoekenViewController *zoekenViewController;
CategorieSelectorViewController *categorieSelectorViewController;
}
@property (nonatomic, assign) ZoekenViewController *zoekenViewController;
@property (nonatomic, assign) CategorieSelectorViewController *categorieSelectorViewController;
@end
ZoekenVarDelegate.m
Code:
#import "ZoekenVarDelegate.h"
@implementation ZoekenVarDelegate
@synthesize zoekenViewController, categorieSelectorViewController;
- (id)init
{
if (self = [super init])
{
categorieSelectorViewController.delegateRef = self;
}
return self;
}
@end
Now the first controller that pops up is the 'ZoekenViewController', this has a searchbox with standard values, there's an options button that will popup a 'CategorieSelectorViewController' with PresentModalViewController, in this screen I want to populate some variables that I pass back to the 'ZoekenViewController'
I added a NSString that needs to be populated from 'CategorieSelectorViewController' to the 'ZoekenViewController':
Code:
@interface ZoekenViewController : [..]
NSString *categoriezoekID;
...
@property (nonatomic, retain) NSString *categoriezoekID;
And in the CategorieSelectorViewController I try to populate it (without success) like:
(part of) CategorieSelectorViewController.h
Code:
#import <UIKit/UIKit.h>
@class ZoekenVarDelegate;
@interface CategorieSelectorViewController : UIViewController <UIPickerViewDelegate> {
NSString *categorieID;
ZoekenVarDelegate *delegateRef;
}
@property (nonatomic, retain) NSString *categorieID;
@property (nonatomic, assign) ZoekenVarDelegate *delegateRef;
@end
(part of) CategorieSelectorViewController.m
Code:
#import "CategorieSelectorViewController.h"
#import "ZoekenViewController.h"
#import "ZoekenVarDelegate.h"
@synthesize delegateRef;
- (IBAction)selecteerCategorie:(id)sender {
if (self.geselecteerdValue == @"Blah") { self.categorieID = @"1";};
self.delegateRef.zoekenViewController.categoriezoekID = self.categorieID;
[self dismissModalViewControllerAnimated:YES];
This is the main part that should happen, a user picks a value from a UIPickerView that is populated through an array and give back a value if it matches, the self.categorieID is properly set (debugger shows), but upon calling self.delegateRef.zoekenViewController.categoriezoekID = self.categorieID; it does nothing, it doesn't seem to populate a variable whatsoever or throw errors..
What am I missing here ?