Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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
Json 在swift中在字典中存储字符串和Int_Json_Swift_Uitableview_Dictionary - Fatal编程技术网

Json 在swift中在字典中存储字符串和Int

Json 在swift中在字典中存储字符串和Int,json,swift,uitableview,dictionary,Json,Swift,Uitableview,Dictionary,我对斯威夫特几乎是新手。我会得到一些元素;其中一个元素是categoryList,它本身有两个元素。我将goodTypeName设置为表的单元格标题,当按下一个单元格时,它需要发送goodTypeName,它是要放置在下一个Url中的数字(Int)。我试图编一本字典,但失败了 UiTable代码::: override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func

我对斯威夫特几乎是新手。我会得到一些元素;其中一个元素是categoryList,它本身有两个元素。我将goodTypeName设置为表的单元格标题,当按下一个单元格时,它需要发送goodTypeName,它是要放置在下一个Url中的数字(Int)。我试图编一本字典,但失败了

UiTable代码:::

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return Global.GlobalVariable.names.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if Global.GlobalVariable.names == []
    {
        self.DisplayMessage(UserMessage: "nothing is available ")
        print("server is nil")
    }
    let cell = UITableViewCell()
    let content = Global.GlobalVariable.names[indexPath.row]
    cell.textLabel?.text = content
    cell.accessoryType = .disclosureIndicator
    return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    print(indexPath.item)
    let next = self.storyboard?.instantiateViewController(withIdentifier: "SVC")
    self.navigationController?.pushViewController(next!, animated: true)
}
我的问题不是在表格中填充它们,我的问题是当选择单元格时,需要将goodtype发送到下一页,因为下一页的url必须有goodtype代码。

您可以使用“prepareSegue”传递数据

覆盖功能准备(对于segue:UIStoryboardSegue,发送方:有吗?){

在StartViewController中,只需分配一个变量来接收数据:

var goodtype = String()
使用导航控制器,但通过此行您可以访问另一个视图控制器属性

         if let startViewController = storyboard.instantiateViewController(withIdentifier: "StartViewController") as? StartViewController {
    startViewController.goodtype = Global.GlobalVariable.goodtype[indexPath.row]
     let navigationController = UINavigationController()
  navigationController.pushViewController(startViewController, animated: true)
    }

代码的描述是误导性的。添加您到目前为止尝试过的内容,并详细说明我更新了描述。我的问题不是传递数据,我的问题是我无法识别每个单元格的goodType!我自己认为我需要一个字典。goodType存储在哪里?您还可以使用类、结构或dict,然后使用indexpath.row只需选择所选单元格的项目。我有一个全局变量,我将把它们存储在那里!如果可能的话,请在postman中查看url以了解我的意思!我也对我的问题感到困惑:| struct mycalss{var goodtype=Int()var goodTypeName=String()}var mydata=[mycalss]()var myclass=mycalss.init(goodtype:101,goodTypeName:“کنجاهسوي”)mydata.append(myclass)mydata[0]。goodTypeName mydata[0].goodtype您有许多选项这是最快的,只需创建一个结构并创建一个结构数组,将数据附加到结构中,然后可以使用indexpath分配它。行您的数据当选择单元格时,我应该如何设置“var myclass=mycalss.init(goodtype:101,goodTypeName:“کنجاهوي”)
         if let startViewController = storyboard.instantiateViewController(withIdentifier: "StartViewController") as? StartViewController {
    startViewController.goodtype = Global.GlobalVariable.goodtype[indexPath.row]
     let navigationController = UINavigationController()
  navigationController.pushViewController(startViewController, animated: true)
    }