Ios 不';t在更改为第三语言(SWIFT)时加载本地html文件
我在xcode项目的lproj文件夹中有3个以3种不同语言本地保存的html文件。在每个Localize.strings文件中,每个html文件名都有键:1)“history\u file”=“history\u en”;2) “历史文件”=“历史文件”;3) “历史文件”=“历史文件”;还有大约一个CompanyViewController和包含3个tableViewCells的TableView。在选择单元格时,在大约公司详细信息中,VC应打开html文件 当我改变语言时,它只能用两种语言工作。我的意思是,如果我将应用程序语言从英语改为哈萨克语并向后,所有功能都正常,但如果我将语言改为俄语,则不会打开html文件。哪种语言被改变并不重要。如果只更改两种语言,它将打开html文件,在更改为第三种语言时,它将打印(“文件读取错误”)。问题出在哪里 在关于公司视图控制器的中:Ios 不';t在更改为第三语言(SWIFT)时加载本地html文件,ios,swift,xcode9,Ios,Swift,Xcode9,我在xcode项目的lproj文件夹中有3个以3种不同语言本地保存的html文件。在每个Localize.strings文件中,每个html文件名都有键:1)“history\u file”=“history\u en”;2) “历史文件”=“历史文件”;3) “历史文件”=“历史文件”;还有大约一个CompanyViewController和包含3个tableViewCells的TableView。在选择单元格时,在大约公司详细信息中,VC应打开html文件 当我改变语言时,它只能用两种语言工
import UIKit
import InteractiveSideMenu
class AboutCompanyViewController: UIViewController, SideMenuItemContent, Storyboardable {
@IBOutlet weak var tableView: UITableView!
var cellImages = ["about_company-4.png", "about_company-2.png", "about_company-3.png"]
var cellLabels = ["history".localized, "production".localized, "partners".localized]
var webPages = ["history_file", "production_file", "partners_file"]
override func viewDidLoad() {
super.viewDidLoad()
self.title = "ABOUT COMPANY".localized
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func openMenu(_ sender: UIButton) {
showSideMenu()
}
}
extension AboutCompanyViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return min(cellImages.count, cellLabels.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AboutCompanyTableViewCell
cell.label.text = cellLabels[indexPath.row]
cell.cellImage?.image = UIImage(named: cellImages[indexPath.row])
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goTo" {
let view = segue.destination as! AboutCompanyDetailVC
let indexPath = self.tableView.indexPathForSelectedRow!
view.selected = self.webPages[indexPath.row]
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let height: CGFloat = 100.0
return height
}
}
import UIKit
import WebKit
class AboutCompanyDetailVC: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: WKWebView!
var selected: String!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "ABOUT COMPANY".localized
loadHtmlFile()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadHtmlFile() {
let preferredLanguage = NSLocale.preferredLanguages[0]
print("\(selected.localized) \(preferredLanguage)")
if let url = Bundle.main.url(forResource: selected!.localized, withExtension: "html") {
let request = URLRequest.init(url: url)
webView.load(request)
} else {
print ("File reading error")
}
}
}
关于公司详情vc:
import UIKit
import InteractiveSideMenu
class AboutCompanyViewController: UIViewController, SideMenuItemContent, Storyboardable {
@IBOutlet weak var tableView: UITableView!
var cellImages = ["about_company-4.png", "about_company-2.png", "about_company-3.png"]
var cellLabels = ["history".localized, "production".localized, "partners".localized]
var webPages = ["history_file", "production_file", "partners_file"]
override func viewDidLoad() {
super.viewDidLoad()
self.title = "ABOUT COMPANY".localized
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func openMenu(_ sender: UIButton) {
showSideMenu()
}
}
extension AboutCompanyViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return min(cellImages.count, cellLabels.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AboutCompanyTableViewCell
cell.label.text = cellLabels[indexPath.row]
cell.cellImage?.image = UIImage(named: cellImages[indexPath.row])
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goTo" {
let view = segue.destination as! AboutCompanyDetailVC
let indexPath = self.tableView.indexPathForSelectedRow!
view.selected = self.webPages[indexPath.row]
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let height: CGFloat = 100.0
return height
}
}
import UIKit
import WebKit
class AboutCompanyDetailVC: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: WKWebView!
var selected: String!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "ABOUT COMPANY".localized
loadHtmlFile()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadHtmlFile() {
let preferredLanguage = NSLocale.preferredLanguages[0]
print("\(selected.localized) \(preferredLanguage)")
if let url = Bundle.main.url(forResource: selected!.localized, withExtension: "html") {
let request = URLRequest.init(url: url)
webView.load(request)
} else {
print ("File reading error")
}
}
}
你检查过没有加载的html文件的目标吗?@sohanvanani,是的,我检查过了。