我正在尝试从UISearchBar存储用户的输入,然后在另一个视图控制器中使用该字符串。这是我的代码:
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
JobDetailViewController *detail =[[JobDetailViewController alloc] init];
[self.navigationController pushViewController:detail animated:YES];
self.jobSearchString = self.searchBar.text;
[detail searchMethod];
NSLog(@"%@",self.jobSearchString);
}
我已经将字符串存储在我在头文件中声明的text属性中,然后我推送到另一个控制器并调用方法。这是我尝试使用存储字符串的下一个视图:
JobbyViewController *mainView = [[JobbyViewController alloc] init];
NSString *searchString = [self.searcherString stringByReplacingOccurrencesOfString:@" " withString:@"-"];
它不断出现(null)。有什么想法吗?
答案 0 :(得分:2)
在@property
上创建JobDetailViewController
并设置
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
JobDetailViewController *detail =[[JobDetailViewController alloc] init];
detail.searchString = self.searchBar.text
[self.navigationController pushViewController:detail animated:YES];
self.jobSearchString = self.searchBar.text;
[detail searchMethod];
NSLog(@"%@",self.jobSearchString);
}