2012-03-17 62 views
0

對於有經驗的程序員來說是一個簡單的問題。我正在嘗試使用搜索欄來鏈接我網站中的另一個搜索欄。 我希望當用戶在應用中的搜索欄上鍵入關鍵字時,webview會顯示該頁面。如何使用搜索欄在iOS應用程序中搜索網站

關鍵是如何鏈接應用程序和網站中的兩個搜索欄,或者Appple不允許執行此操作。

我是一個非常新的ios開發人員。

ps。在我的網站的搜索欄:http://www.searchandbuy.com.tw/

回答

0

使用服務器端的JSON(我的偏好),它可以通過做一些像搶從您的網站查詢的數據:

NSURL *baseUrl = [NSURL URLWithString:@"http://www.searchandbuy.com/tw/"]; 
NSString *args = [NSString stringWithFormat:@"%@",/*some variable in which you store your user's input here*/] 
args = [args stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 

NSString *urlString = [NSString stringWithFormat:@"%@search?q=%@",baseUrl,args]; 
NSLog(@"%@",urlString); 
NSURL *url = [NSURL URLWithString:urlString]; 
//NSLog(@"%@",urlString); 
NSData *jsonData = [NSData dataWithContentsOfURL:url]; 
NSError *error; 
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error]; 
NSMutableArray *searchResults = [json objectForKey:@"searchResults"];