2013-10-18 66 views
0

我試圖從UISearchBar存儲用戶的輸入,然後在另一個視圖控制器中使用該字符串。這裏是我的代碼:從UISearchBar傳遞字符串到另一個viewController

-(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); 
} 

我已經保存在我在我的頭文件中聲明瞭一個文本屬性字符串,我然後推到另一個控制器,並調用一個方法。下面是我嘗試使用存儲的字符串的下一個視圖:

JobbyViewController *mainView = [[JobbyViewController alloc] init]; 

NSString *searchString = [self.searcherString stringByReplacingOccurrencesOfString:@" " withString:@"-"]; 

它始終以(null)形式出現。有任何想法嗎?

回答

2

創建您JobDetailViewController一個@property並將其設置

-(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); 
} 
+0

哎呀,認爲有詳細的物業哈哈。太明顯了。 –

+0

哎呀!我知道我錯過了一些東西!衛生署!謝謝Bot! –

相關問題