gpt4 book ai didi

json - 从选择图像或按钮获取 JSON url 到 Swift 4 中的字符串

转载 作者:可可西里 更新时间:2023-11-01 01:59:05 25 4
gpt4 key购买 nike

你好 Stack Overflow 社区。

我目前正在处理我的新应用程序的界面。当我尝试从 Web 服务器获取一些 JSON 数据时,我在将它实现到应用程序时遇到了一个小问题(不知道我应该怎么做)。

基本上我想要得到的是一个按钮或图像,当我选择它时,我会在我的 JSON Url 中得到一个选择

水果示例:

Select FRUIT

  1. 我选择了 banana 并将获得此 JSON url:

    "https://www.examplewithfruits.com/getsomeFruit"+"banana"+"fromList"

  2. 我选择了 apple 并将获得此 JSON url:

    "https://www.examplewithfruits.com/getsomeFruit"+"apple"+"fromList"

重要的是,用户不需要在框中写下单词,而是选择图像或按钮。选择一些图像后,新事件将加载到新页面上。也可以将图像和文本框结合起来吗?(例如写下用户名)

如果这个问题很愚蠢,我很抱歉,但我真的不知道什么是解决这个问题的最佳方法。将不胜感激一些示例或链接。谢谢!

最佳答案

class ViewController: UITableViewDelegate,UITableViewDataSource{

var imageArray =["Banana","Apple"]
override func viewDidLoad() {

super.viewDidLoad()
// Do any additioa lf
self.tableView.dataSource = self
self.tableView.delegate = self
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imageArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell
cell.imageView?.image = UIImage(named: imageArray[indexPath.row])
return Cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

// Your Json url

var url = "https://www.examplewithfruits.com/getsomeFruit"+"\(self.imageArray[indexpath.row])"+"fromList"
}
}

关于json - 从选择图像或按钮获取 JSON url 到 Swift 4 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48020950/

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