gpt4 book ai didi

ios - SWIFT TableView 错误

转载 作者:搜寻专家 更新时间:2023-11-01 07:31:21 25 4
gpt4 key购买 nike

class MasterViewController: UITableViewController {

let firstTable = [String]()
let secondTable = [String]()

var path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt")
var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil)
var content = (data)
var line: [String] = content.componentsSeparatedByString("\n")

错误:

'MasterViewController.Type' does not have a member named 'path'

@dip 的下一个问题 >> 为什么表格打印初始空字符串?文本打印在第二个单元格中而不是从 0 开始

var path: String?
var data: String?
var TableView1 = [String]()

override func viewDidLoad() {
super.viewDidLoad()

self.path = NSBundle.mainBundle().pathForResource("textFile", ofType: "txt")
self.data = String(contentsOfFile:path!, encoding: NSUTF8StringEncoding, error: nil)
if var content = (data){
//var line: [String] = content.componentsSeparatedByString("\n")
var chp: [String] = content.componentsSeparatedByString("#")

TableView1 += chp
}...

最佳答案

对于计算属性,您必须通过 setter 方法访问,例如使可选的全局变量像

var path:String?

然后让我们从 inside viewDidload 中设置值,比如

self.path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt")

您的错误将会消失!希望对您有所帮助!

关于ios - SWIFT TableView 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32367707/

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