如何在iPhone设备中保存用户最喜欢的文章
我有新闻门户应用程序,我希望用户在按下按钮时将当前正在阅读的整篇文章保存到 iPhone 设备,以便他可以随时访问它。我还想知道一篇文章是否保存到用户列表而不是保存两次
I have newsportal application and i want user when hitting a button to save the whole article that is reading at the moment, to the iphone device so that he can access it whenever he wants. I also want to know if an article is save to the users list and not to save it twice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 NSUserDefaults。
prefsObject 是您为保存您的最爱而编写的类。它可能只保存数组,但您可以在其中放置用于搜索、添加、删除等的便利函数。
urlString 是一个包含文章 URL 的 NSString。
addStringToURL 是将 urlString 添加到 NSMutableArray 的方法。
getNSArrayOfURLS 是一个返回包含所有 URL 的 NSMutableArray 的方法。
后面加载数据的
initWithNSArray是用NSArray加载NSMutableArray的方法,使用NSArray的方法mutableCopy,返回一个NSMutableArray。该方法可能看起来像
请注意,我尚未测试这个确切的代码,但我在我的应用程序中使用了类似的版本。
您可以在此处找到在 NSMutableArray 中搜索现有 URL 的解决方案< /a>.
You will want to save using NSUserDefaults.
prefsObject is a class you wrote to hold your favourites. It might only hold the array, but you can put convenience functions for searching, adding, removing, etc. in there.
urlString is an NSString containing the URL to the article.
addStringToURL is a method that adds the urlString to an NSMutableArray.
getNSArrayOfURLS is a method to return the NSMutableArray with all of the URLs.
Later, to load the data
initWithNSArray is a method to load the NSMutableArray with an NSArray, using the NSArray method mutableCopy, which returns an NSMutableArray. That method might look like
Note that I have not tested this exact code, but I used a similar version in my app.
You can find a solution of searching the NSMutableArray for existing URLS here.