【问题标题】:How to Bookmark HTML files in iOS?如何在 iOS 中为 HTML 文件添加书签?
【发布时间】:2014-07-03 08:00:23
【问题描述】:

我有一堆本地 HTML 文件,我想在应用程序中创建书签功能。 当用户按下书签按钮时,它将数据保存在核心数据中。 该怎么做?

【问题讨论】:

  • 到目前为止你做了什么?

标签: html ios xcode plist nsbundle


【解决方案1】:

书签功能通常只包括保存指向现有数据的链接。为什么需要 Core Data 来保存它?如果您有很多书签,那将是有意义的。在这一点上,这对我来说似乎有点矫枉过正。但是,您可以使用 MagicalRecord (https://github.com/magicalpanda/MagicalRecord) 来完成 CoreData 的繁重工作。

 // create a bookmark record, you can also add title, image, timestamp, etc...
 NSDictionary *bookmarkRecord = @{"url":"http://www.igraczech.com"};

 // prepare dictionary for all the bookmark records you want to save
 NSMutableDictionary *records = [NSMutableDictionary new];
 [records addObject:bookmarkRecord forKey:@"Bookmark title"];

 // this saves the 'records' dictionary (immutable by default), size limit is about a megabyte or two
 [[NSUserDefaults standardUserDefaults] setObject:records forKey:@"bookmarks"];
 [[NSUserDefaults standardUserDefaults] synchronize];

 // this loads bookmarks into mutable dictionary so you can add/edit/remove/save another one safely
 id savedBookmarks = [[NSUserDefaults standardUserDefaults] objectForKey:@"bookmarks"];

 // here the bookmarks are stored, you should use ivar/property instead of this example
 NSMutableDictionary *bookmarks = [NSMutableDictionary new];

 if (savedBookmarks)
 {
     bookmarks = [bookmarks addContentsFromDictionary:savedBookmarks];
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 2013-11-18
    • 2019-08-18
    • 2014-03-22
    • 2011-07-24
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多