2
我試圖使用iPhone上的Xpath從here中提取天氣信息。到目前爲止,它解析所有的數據,但我堅持如何提取內容並將其顯示在表格中。 這是我到目前爲止有:如何在iPhone上顯示Xpath
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[ @"http://aviationweather.gov/adds/metars/?station_ids=1234&std_trans=translated&chk_metars=on&hoursStr=most+recent+only&submitmet=Submit"stringByReplacingOccurrencesOfString:@"1234" withString:self.title]]];
TFHpple * doc = [[TFHpple alloc] initWithHTMLData:data];
NSArray * elements = [doc searchWithXPathQuery:@"//table[1]//tr"];
NSLog(@"%@", elements);
TFHppleElement * element = [elements objectAtIndex:0];
[element content]; // Tag's innerHTML
[element tagName]; // "a"
[element attributes]; // NSDictionary of href, class, id, etc.
[element objectForKey:@"href"]; // Easy access to single attribute
如果有人需要看看它的輸出到目前爲止,讓我知道。
感謝, 安德魯
在Google上查看「UITableView教程」,例如, http://www.google.com/search?client=safari&rls=zh-CN&q=uitableview+tutorial&ie=UTF-8&oe=UTF-8 – 2012-01-13 21:11:50
它不是顯示我不明白的表格,它組織數據以便我可以顯示它。謝謝 – Boos1993 2012-01-13 21:16:05
我想我不明白。你想展示什麼數據?如果你可以把你的數據放到一個數組中,那麼你可以把它放到一個表中。看起來你已經在'elements'中有了這個數組,這只是一個循環遍歷數組來製作表格單元的問題。 – 2012-01-13 21:29:03