dengzemiao / DZMeBookRead

支持项目使用!最完整小说阅读器Demo!仿iReader(掌阅),QQ阅读 ... 常用阅读器阅读页面,支持 翻页效果(仿真,覆盖,平移,滚动,无效果)、字体切换、书签功能、阅读记录、亮度调整、背景颜色切换 ...
MIT License
1.23k stars 325 forks source link

章节id错误,导致倒数第二章节的无法翻页到最后章节。 #30

Open DamonChen117 opened 6 years ago

DamonChen117 commented 6 years ago

出现下面情况是所有的章节id都多加了1,导致倒数第二章节的无法翻页到最后章节。

// 说不定没有内容 则不需要添加到列表 if readChapterModel.content.isEmpty {continue}

dengzemiao commented 6 years ago

@DamonChen117 你的意思就是没有开始 然后导致所有章节ID 都加了1 对吧

dengzemiao commented 6 years ago

` // 有前言 var isPreface:Bool = true

        // 便利
        for i in 0...count {

            // 章节数量分析:
            // count + 1  = 搜索到的章节数量 + 最后一个章节,
            // 1 + count + 1  = 第一章前面的前言内容 + 搜索到的章节数量 + 最后一个章节
            print("总章节数:\(count + 1)  当前解析到:\(i + 1)")

            // range
            var range = NSMakeRange(0, 0)

            var location = 0

            if i < count {

                range = results[i].range

                location = range.location
            }

            // 创建章节内容模型
            let readChapterModel = DZMReadChapterModel()

            // 书ID
            readChapterModel.bookID = bookID

            // 章节ID
            readChapterModel.id = "\(i + NSNumber(value: isPreface).intValue)"

            // 优先级
            readChapterModel.priority = NSNumber(value: (i - NSNumber(value: !isPreface).intValue))

            if i == 0 { // 开始

                // 章节名
                readChapterModel.name = "开始"

                // 内容
                readChapterModel.content = ContentTypesetting(content: content.substring(NSMakeRange(0, location)))

                // 记录
                lastRange = range

                // 说不定没有内容 则不需要添加到列表
                if readChapterModel.content.isEmpty {

                    isPreface = false

                    continue
                }

            }else if i == count { // 结尾`
DamonChen117 commented 6 years ago

是的,我本地是这么改的:

var id = 1 // 便利 for i in 0...count {

if i == 0 { ... } }else if i == count { ... } }else { ... }

// 章节ID readChapterModel.id = "(id)" // 优先级 readChapterModel.priority = NSNumber(value: id) id += 1

}