使用按钮和 UITableView 快速下拉

Posted

技术标签:

【中文标题】使用按钮和 UITableView 快速下拉【英文标题】:Dropdown in swift with button and UITableView 【发布时间】:2019-06-04 06:42:19 【问题描述】:

我想使用 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)

它在我的输出中显示--> ()

谁能帮我解决这个问题,好吗?

【问题讨论】:

let buttonTitle = btntitle.setTitle("\(fruits[indexpath.row])", for:.normal) 更改为let buttonTitle = fruits[indexPath.row] 【参考方案1】:

您正在将函数 setTitle(返回 void)分配给您的 buttonTitle 变量。当您打印该变量时,您会看到 ()

您可能会在该行看到警告。

修改如下:

let buttonTitle = fruits[indexpath.row]
btntitle.setTitle(buttonTitle, for: .normal)

【讨论】:

以上是关于使用按钮和 UITableView 快速下拉的主要内容,如果未能解决你的问题,请参考以下文章