当我点击搜索按钮时,我希望传递数据并从Search VC
(选项卡索引4)转到Classes VC
(选项卡索引2)。 Search VC
已嵌入Tab View Controller
。 Classes VC
嵌入了Tab View Controller
和Navigation Controller
。见附图。
我尝试在以下代码中使用seague,但我丢失了Tab Bar
SearchToClass
的密码,从Search VC
到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
答案 0 :(得分:0)
这是你能做的。如果您希望将数据从搜索vc传递到类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])
更改为标签
self.tabBarController?.selectedIndex = 2
注意:使用标签栏控制器时不需要segue