I am getting this error
[ResultViewController setSearchFields:IndexPath:]: unrecognized selector sent to instance 0xc448840
I have a navigation controller stack in which I am using delegates to pass information back to a previous view in the navigation stack.. However I think I am doing something wrong when I am declaring the delegate.
My navigation stack looks like this.
view 0 (mainmenu)
-- view 1 (SearchViewController)
--- view 2 (ResultViewController) - where I set the delegate of the new view being loaded
---- View 3 (SubViewController) - this is where my delegates reside
What I am doing is popping to view1 and passing the delegate information to that view however by doing so I am getting this error… I am wondering if I have to set the delegate for view 3 in view 1 where I end up passing the information… is that correct??
If so what do I have to think about when setting the delegate? How do I call it from view 1
This is how I’m setting up my delegate in SubViewController
subvc.h
@protocol PassSubSearchData <NSObject>
@required
- (void) setSearchFields:(NSArray *)modArray IndexPath:(NSIndexPath *)modIndexPath;
@end
@interface VehicleSubResultViewController : UITableViewController <NSXMLParserDelegate> {
//..
//Delegate for passing Mod and SubMod data back to VehicleSearchViewController
id <PassSubSearchData> delegate;
//..
//Delegate for passing Mod and SubMod data back to VehicleSearchViewController
@property (strong) id delegate;
subvc.m
#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] setSearchFields:tempModArray IndexPath:tempModIndexPath];
//This pops to the View 1 - SearchViewController
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
Then In my SearchViewController this is how I am setting the delegate stuff up
searchvc.h
#import "SubViewController.h"
@interface SearchViewController : UITableViewController <PassSubSearchData> {
//..
searchvc.m
- (void) setSearchFields:(NSArray *)modArray IndexPath:(NSIndexPath *)modIndexPath
{
modSearchObjectString = [[modArray valueForKey:@"MOD"] objectAtIndex:0];
modSearchIndexPath = modIndexPath; // Sets the selected IndexPath from the subview
NSLog(@"%@", modSearchObjectString);
NSLog(@"%@", modResultIndexPath);
[self.tableView reloadData];
}
That pretty much sums it up.. sorry for the delay.
So from what I can tell, storing the information into a file and then bringing it back down when it is needed might be a simpler way to achieve what you want. Something (I know, oversimplified) like this:
Later you can get that string back by using:
You can proceed in this same way with the information that you need to transfer.
Another alternative is to create a property in the view controller receiving the data:
then before you pop to the view controller you do:
then once you go to that controller, that property will be set with whatever string you set it to in
And in these ways you can pass information between view controllers. Good luck!