0

我正在尝试创建一个带有两个标题(帐户、支持)和部分文本标题的 TableView。但我遇到了错误

我遵循了这个问题的答案:如何使用 swift 使用两个不同的数组填充 tableview 中的两个部分?

错误: 在此处输入图像描述 和: 在此处输入图像描述

这是我的代码:

 var myTitles = [["Delete current photo","Change profile picture","Change username","Change password"],["Help","Report a problem"]]

let headerTitles = ["Acount", "Support"]

override func viewDidLoad() {
    super.viewDidLoad()

}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return myTitles[section].count
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return 3 //This is not complete yet.
}

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    if section < headerTitles.count {
        return headerTitles[section]
    }

    return nil
}

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

    cell.textLabel?.text = myTitles[indexPath.section][indexPath.row]

    return cell
}
4

1 回答 1

0

首先,您在哪里获得section价值:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return myTitles[section].count
}

将其更改为return myTitles.count.

于 2016-04-01T16:32:40.250 回答