gpt4 book ai didi

ios - 在 View Controller 之间移动数据,并在 Swift 的 Web View 中显示移动的数据

转载 作者:行者123 更新时间:2023-11-28 13:32:11 25 4
gpt4 key购买 nike

我正在通过 WebView 显示书页。

我创建了一个显示目录的 TableView Controller 。我想在单击目录表格单元格时加载 WebView。

如果当前正在查看的页面是10,则web View 中显示的是第10页的内容。

当我按下要在目录 View Controller 中显示的目录(第 19 页)时,目录 TableView 消失,我想将第 19 页的内容显示为 Web View 。

但是,在 Storyboard中,在 WebView 上显示书籍的 Controller (ReadBookVC) 和目录 TableView Controller (ChapterVC) 没有连接。

 func pageView(_ page: Int) {
let request = URLRequest(url: URL(string: "example.com?book_no=\(Int(bookNo ?? "") ?? 0)&book_page=\(page)")!)
// request load
webView?.load(request)
}

pageView 函数用于在 ReadBookVC 的 WebView 中显示书籍。

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func chapterReload() -> Void {
readBookViewController?.pageView(Int(chaptersList?.chapters[indexPath.row].chapterPage ?? "") ?? 0)

}

dismiss(animated: true, completion: chapterReload)

}

我将目录的页面 (Int (chaptersList? .Chapters [indexPath.row] .chapterPage ??") ?? 0) 传递给 ReadBookVC 的 pageView 函数, Int (chaptersList? .Chapters [indexPath.row] .chapterPage ??"") ?? 0 网页 View 中的页面。

但是执行chapterReload函数的时候

readBookViewController? .pageView (Int (chaptersList? .chapters [indexPath.row] .chapterPage ?? ") ?? 0)

我注意到我根本没有运行这段代码。

为什么 readBookViewController? .PageView (Int (chaptersList? .Chapters [indexPath.row] .chapterPage ?? ") ?? 0)

代码没有运行吗?

最佳答案

您需要做的更改很少:

第VC章中:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
chapterReload(pageNumber: indexPath.row)
//dismiss(animated: true, completion: chapterReload) No need to dismiss
}

func chapterReload(pageNumber: Int) {
let readBookViewController = self.storyboard?.instantiateViewController(withIdentifier: "ReadBookViewController") as! ReadBookViewController //Give Storyboard ID as ReadBookViewController for ReadBookViewController in storyboard
readBookViewController?.chapterPageNumber = pageNumber
self.present(readBookViewController, animated: true, completion: nil)
}

然后在ReadBookViewController中声明一个变量。

var chapterPageNumber: Int!

ReadBookViewController 中使用 chapterPageNumber 来显示页面。完成后,您应该关闭 ReadBookViewController

self.dismiss(animated: true, completion: nil)

Why readBookViewController? .PageView (Int (chaptersList? .Chapters [indexPath.row] .chapterPage ?? ") ?? 0)

因为您要解雇一个 Controller 并且在完成时您只是调用该 Controller 的一个函数。如何调用没有实例(已关闭或弹出)的 Controller 的函数?

关于ios - 在 View Controller 之间移动数据,并在 Swift 的 Web View 中显示移动的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57194934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com