我想使用 swift 在我的 ios 应用程序中使用下拉菜单。到目前为止,我通过观看下拉视频已经实现了一切 I have created drop down using this link
但是当我打印按钮标题时
func tableView(_ tableView: UITableView, didSelectRowAt indexPath:IndexPath{ let buttonTitle = btntitle.setTitle("\(fruits[indexpath.row])", for:.normal) print(buttonTitle)}
它在我的输出中显示 --> () <-- 。 但我想要从代码中选择的项目名称。
有人可以帮我解决这个问题吗?
最佳答案
您正在将函数setTitle(返回void)分配给您的buttonTitle 变量。当您打印该变量时,您会看到 () <- 因为它是空返回。
您可能会在该行看到警告。
修改如下:
let buttonTitle = fruits[indexpath.row]
btntitle.setTitle(buttonTitle, for: .normal)
关于swift - 带按钮和 UITableView 的快速下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56438609/