从网站提取数据并将其存储到数组中 - iPhone SDK
我正在尝试编写一个应用程序来搜索网站,并获取所有结果并将它们放入自定义表格中。我是 Objective-C 和 iPhone SDK 菜鸟,希望这个逻辑就是我想要实现的目标:
1)搜索多个搜索引擎并从每个网站中提取所有数据,将每个数据存储到不同的数组中(例如示例:在 Google、Yahoo 和 Bing 中搜索“鞋子”,并获取所有不同的搜索结果、超链接等,并将它们存储到三个不同的数组中)
2)从每个数组中提取数据,然后放入表中(Interface Builder 中的表视图)
我还编写了一些伪代码,希望大家可以查看以发现潜在的设计缺陷和逻辑错误。我想如果我们能够解决逻辑和设计错误,那么将一些语法放在一起可能会相对容易吗?
Class SearchWebsites:
NSString *websiteURL = "http://www.searchengine.com/keywords=";
UISearchBar SearchButtonClicked{
NSString *websiteURL = websiteURL+searchBarText.text;
Go to websiteURL;
Extract all hyperlink data from websiteURL and store into NSArray *websiteData;
Load SearchResults.xib;
}
End Class SearchWebsites
Class SearchResults:
Table data = NSArray *websiteData;
End Class SearchResults
我假设我需要声明全局变量,以便可以从不同的类调用它们......对吗?执行此操作的语法是什么?我如何在 IB 中进行设置?对于第一个应用程序,我是否贪得无厌?
感谢您的帮助!
I am trying to write an app that searches a website, and takes all of the results and puts them into a customized table. I am an Objective-C and iPhone SDK noob, and am hoping that this logic is what I am trying to accomplish:
1) Searching multiple search engines and pulling all of the data off of each website, storing each into a different array (for example: Searching Google, Yahoo, and Bing for "Shoes", and taking all of the different search results, hyperlinks and all, and storing them into three different arrays)
2) Pulling the data out of each array, and putting into a table (Table view in Interface Builder)
I've also written some pseudo-code that I am hoping that you all can look over to see potential design flaws, and logic errors. I figure if we can get logic and design errors out of the way, throwing some syntax together could be relatively easy?
Class SearchWebsites:
NSString *websiteURL = "http://www.searchengine.com/keywords=";
UISearchBar SearchButtonClicked{
NSString *websiteURL = websiteURL+searchBarText.text;
Go to websiteURL;
Extract all hyperlink data from websiteURL and store into NSArray *websiteData;
Load SearchResults.xib;
}
End Class SearchWebsites
Class SearchResults:
Table data = NSArray *websiteData;
End Class SearchResults
I am assuming that I need to declare global variables, so that they can be called from different classes......right? What's the syntax for doing this? How do I set this up in IB? Did I bite off more than I can chew for this first app?
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是一个需要在这里回答的大问题:) ...首先,阅读 Apple 关于 Objective-C 的文档可能会对您有用 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/ introObjectiveC.html 。
然后你可能会在开发者网站上搜索 UITableView 编程指南,但这里有一个很好的教程: http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populate-uitableview-with-an-nsarray/
Moszi
i think this is really big question to be answered here :) ... First of all it might be useful for you to read the documentation from Apple about Objective-C http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html .
Then you might search for UITableView programming guide on the developer website, but there is a nice tutorial here: http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/
Moszi
您可能想使用 NSMutableDictionary 构建链接列表 - 如果需要,您可以像数组一样迭代它,但也可以按名称查找条目。
iPhone SDK 开发 将教您所需的基础知识。
You might want to use NSMutableDictionary to build a list of links - you can iterate it like an array if need be, but can also look up entries by name.
iPhone SDK Development will teach you the basics you are after.