Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法将“Int”类型的值转换为预期的参数类型“String.Index”_Ios_Swift - Fatal编程技术网

Ios 无法将“Int”类型的值转换为预期的参数类型“String.Index”

Ios 无法将“Int”类型的值转换为预期的参数类型“String.Index”,ios,swift,Ios,Swift,我得到这个错误: 无法将“Int”类型的值转换为预期的参数类型“String.Index” 在线目标[0]。删除:indexath.row。我如何解决这个问题 这是我的密码: import UIKit class GoalsViewController: UIViewController { @IBOutlet weak var tableView: UITableView! var Goals: [String] = ["goal 1", "goal 2", "goal

我得到这个错误:

无法将“Int”类型的值转换为预期的参数类型“String.Index”

在线目标[0]。删除:indexath.row。我如何解决这个问题

这是我的密码:

import UIKit

class GoalsViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

    var Goals: [String] = ["goal 1", "goal 2", "goal 3"]

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self
    }
}

extension GoalsViewController: UITableViewDataSource, UITableViewDelegate {

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         if indexPath.section == 0 {
             Goals[0].remove(at: indexPath.row)
             tableView.reloadData()
         }
     }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return Goals.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "GoalCell_1", for: indexPath)
        cell.textLabel?.text = Goals[indexPath.row]
        return cell
    }

}

您需要删除数组元素而不是字符串中的子字符串,替换显示错误的行:

Goals.remove(at: indexPath.row)
目标是一个数组

var Goals: [String] = ["goal 1", "goal 2", "goal 3"]
这里选择数组“[0]”的第一个元素并尝试从中“.remove”,但它是一个字符串

Goals[0].remove(at: indexPath.row)
如果要从目标数组中删除字符串:

Goals.remove(at: indexPath.row)

你到底想在这里实现什么?我试图在单击单元格后将其删除,然后最终将其移动到新的表视图中