I wish to pass data and go from Search VC
(tab index 4) to Classes VC
(tab index 2) when I click on the Search Button. Search VC
is embedded in a Tab View Controller
. Classes VC
is embedded in both a Tab View Controller
and a Navigation Controller
. See the attached pic.
I have tried using seague on the following code, but I lost my Tab Bar
SearchToClass
from Search VC
to Classes VC
#import "Search.h"
#import "Classes.h"
#import "ClassNavigationController.h"
@interface Search(){
NSString *sURL;
}
@end
@implementation Search
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)btnSearch:(UIButton *)sender {
NSLog(@"This is the slider %@", lblStart.text);
sURL = @"&Start=";
sURL = [sURL stringByAppendingString:sStartTime];
sURL = [sURL stringByAppendingString:@"&End="];
sURL = [sURL stringByAppendingString:sEndTime];
[self performSegueWithIdentifier:@"SearhToClass" sender:self];
//======== I have also tried the following but couldn't pass the data and I lost the Tab Bar as well======================================
//ClassNavigationController *fromSearch = (ClassNavigationController*)[storyboard instantiateViewControllerWithIdentifier:@"Classes"];
//[fromSearch setModalPresentationStyle:UIModalPresentationFullScreen];
//[self presentViewController:fromSearch animated:NO completion:nil];
//===================================================================
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
Classes *target = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"SearchToClass"]) {
NSLog(@" To ClassesDet sURL : %@", sURL);
target.urlFromSearch = sURL;
}
}
@end
Here is what you can do. If you want data to be passed from search vc to classes vc.
NotificationCenter.default .addObserver(forName:NSNotification .Name(rawValue: "testKey"), object:nil, queue:nil, using: yourMethodToBeCalled) //set notification observer
NotificationCenter.default .post(name: NSNotification .Name(rawValue: "testKey"), object: nil, userInfo: ["myData": true, "myList": myList])
Change to tab
self.tabBarController?.selectedIndex = 2
Note: No need for a segue when you are using a tab bar controller