I am passing some information from one view to the other using delegates, However when I select a tableview cell I am passing the data to the delegate that will pas the information back to a view on the stack.. it makes it back to that view but doesn’t actually go into the delegate method when the views change…
Here is where I set up my delegate.
subViewController.h
#import <UIKit/UIKit.h>
@protocol PassSubSearchData <NSObject>
@required
- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath;
@end
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
id <PassSubSearchData> delegate;
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
@property (strong) id delegate;
//This is how I use it
subViewController.m
#import "MainViewController.h"
#import "SubViewController.h"
@implementation VehicleSubResultViewController
//...
//Delegate for passing Model and SubModel data back to VehicleSearchViewController
@synthesize delegate;
//...
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Access selected cells content (cell.textLabel.text)
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Predicates restrict the values that will be returned from the query
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"SUB",cell.textLabel.text];
filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];
[[self delegate] setModSearchFields:tempModArray modIndexPath:tempModIndexPath setSubMod:filterArray subModIndexPath:indexPath];
//This pops to the VehicleSearchViewController view
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
Then in the main view
MainViewController.h
#import "SubViewController.h"
@interface VehicleSearchViewController : UITableViewController <PassSubSearchData> {
//...
MainViewController.m // However this part of the code is never accessed
- (void) setModSearchFields:(NSArray *)modArray modIndexPath:(NSIndexPath *)modIndexPath setSubMod:(NSArray *)subModArray subModIndexPath:(NSIndexPath *)subModIndexPath
{
modObjectString = [[modArray valueForKey:@"MOD"] objectAtIndex:0];
modIndexPath = modIndexPath; // Sets the selected IndexPath from the subview
subModObjectString = [[modelArray valueForKey:@"SUBMODEL"] objectAtIndex:0];
subModIndexPath = subModResultIndexPath; // Sets the selected IndexPath from the subview
NSLog(@"%@", modObjectString);
NSLog(@"%@", modIndexPath);
NSLog(@"%@", subModObjectString);
NSLog(@"%@", subModIndexPath);
[self.tableView reloadData];
}
So thats it, I’m just not sure what I’m missing if anyone knows any help would be appreciated.
Most likely the delegate never got set, so it is nil and nothing happens.