gpt4 book ai didi

ios - Swift:使用 TableView 外部的按钮并检查选择了哪一行

转载 作者:行者123 更新时间:2023-11-28 15:59:49 25 4
gpt4 key购买 nike

我有一个 tableView。它不是 tableViewController。在我的 ViewController 上,我有一个带有 15 个选项的 tableView。我可以毫无问题地选择每个选项。所以我想使用一个不在 View Controller 内部的按钮,当我选择它时,它决定了表格的哪一行被选中。现在,我只是看到一条警告消息,其中显示了所选的行。

基本上,表格的每一行都是不同的种族:矮人、 Sprite 等……表格 View 的正下方是一个按钮。当我单击该按钮时,我希望出现一个警告,说明已选择哪一行。

这是我目前所拥有的:

class raceViewController: UIViewController, UITableViewDelegate, UITableViewDataSource
{

@IBOutlet var raceInfoBtn: UIButton!
@IBOutlet var raceTable: UITableView!

// defines an array with the races
let races = ["Dwarf", "Elf","Gnome","Half-Elf","Half-Orc","Halfling","Human", // core races
"Ifrit","Oread","Sylph","Tengu","Undine", // featured races
"Kitsune","Nagaji","Wayang"] // uncommon races// uncommon races

// defines the stats array to correspond to the races array
let stats = ["+2 Con & Wis, -2 Chr","+2 Dex & Int, -2 Con","+2 Con & Dex, -2 Str","Click to add","Click to add","+2 Dex & Chr, -2 Str","Click to add", // core races
"+2 Dex & Chr, -2 Wis","+2 Str & Wis, -2 Chr","+2 Dex & Int, -2 Con","+2 Dex & Wis, -2 Str","+2 Dex & Wis, -2 Str", // featured races
"+2 Dex & Chr, -2 Str","+2 Str & Chr, -2 Int","+2 Dex & Int, -2 Chr"] // uncommon races// uncommon races] //core

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

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "raceCell")
//cell.textLabel?.text = races[indexPath.row] + stats[indexPath.row]
cell.textLabel?.text = races[indexPath.row]
cell.detailTextLabel?.text = stats[indexPath.row]

return (cell)
}

@IBAction func raceInfoBtn(_ sender: Any)
{
{
let alertController = UIAlertController(title: "iOScreator", message:
"dwarf", preferredStyle: UIAlertControllerStyle.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.default,handler: nil))

self.present(alertController, animated: true, completion: nil)
}
}

}

IBAction raceInfoBtn 中,我希望它检查实际选择了哪一行。

最佳答案

raceTable.indexPathForSelectedRow 应该为您提供选定的索引路径,您可以使用它在警报中显示正确的信息。

关于ios - Swift:使用 TableView 外部的按钮并检查选择了哪一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41252213/

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