gpt4 book ai didi

xcode - 从 Tableview 到 Webview 详细信息的本地文件

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

我有一个 UITableView ,其每一行都必须将我带到包含 UIWebView 的详细信息页面。Tableview 的每个项目(行)都有一个本地 HTML 文件。使用此代码,我支持相同的 HTML 文件:

@IBOutlet weak var webView: UIWebView!

override func viewDidLoad() {
super.viewDidLoad()
let localfilePath = NSBundle.mainBundle().URLForResource("yyy", withExtension: "html")
let myRequest = NSURLRequest(URL: localfilePath!)
webView.loadRequest(myRequest)
}

如何为每一行分配与其匹配的 HTML 文件?

最佳答案

在我的 TableViewController 中:

    class IntroTableViewController: UITableViewController {
var labelintro = [String]()
var webAddresses = [String]()

override func viewDidLoad() {
super.viewDidLoad()

labelintro = ["Avant-propos", "Zone Sakalava", "Pronontiation", "Conjugaison", "Verbes indispensables","Grammaire & synthaxe","Mots indispensables","Les comptes","Le temps", "Termes de politesse", "La famille", "Se déplacer", "Le commerces", "Les vêtements", "Se loger", "Nourritures, épices & condiments", "Nature & paysages", "Ville, village", "L'école", "La flore", "La faune", "Santé & corps", "Artisanat, tradition & sacré", "Expressions courantes"]


webAddresses = ["xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html","xxx.html", "yyy.html"]

}

override func prepareForSegue(segue: UIStoryboardSegue,
sender: AnyObject?) {

if segue.identifier == "gotodetail" {
_ = segue.destinationViewController
as! DetailIntroViewController
}
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return labelintro.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("texteintrocell", forIndexPath: indexPath) as! IntroTableViewCell


let row = indexPath.row
cell.labelIntro.text = labelintro[row]

return cell
}

}

在我的 DetailViewController 中:

    class DetailIntroViewController: UIViewController {



@IBOutlet weak var webView: UIWebView!


override func viewDidLoad() {
super.viewDidLoad()


let localfilePath = NSBundle.mainBundle().URLForResource(self.selectedHTMLFileName, withExtension: "html")

}
}

关于xcode - 从 Tableview 到 Webview 详细信息的本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693970/

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