简体   繁体   English

更新Uitableview单元格按钮标题

[英]Update Uitableview cells button title

I have a UiTableview with custom cells. 我有一个带有自定义单元格的UiTableview。 In each cell I have a button, the button's title is set to "Upload" when the cell is created. 在每个单元格中都有一个按钮,在创建单元格时,按钮的标题设置为“上传”。 When click the button, it Uploads a project to the server and the button title becomes "Uploaded". 单击按钮后,它将项目上载到服务器,并且按钮标题变为“已上传”。 And i want to have a button in the navigation bar, when pressed, it reset all the buttons' title (buttons in UITableview cells) to "upload", I've tried to use reloadData function, but it didn't work. 我想在导航栏中有一个按钮,当按下该按钮时,它将所有按钮的标题(UITableview单元格中的按钮)重置为“上载”,我试图使用reloadData函数,但没有用。 I'm very new to iOS and swift, any help? 我对iOS还是很陌生,很快,有什么帮助吗? Thanks in advance! 提前致谢!

Table View Cells get reused, so we need some object, such as an array, to keep the state of each cell. 表视图单元格得到重用,因此我们需要一些对象(例如数组)来保持每个单元格的状态。

As soon as the project item is loaded to the server - we need to update the item in the array at the corresponding index (based on cell's Index Path). 将项目项加载到服务器后,我们需要以对应的索引(基于单元格的索引路径)更新数组中的项。 Probably, each item in the array must be a Dictionary. 数组中的每个项目可能都必须是一个词典。

So initially, the Dictionary's contents will be: 因此,最初,该词典的内容将是:

{
    "project_name": "Project 1",
    "project_label": "Upload"
}

After upload is finished: 上传完成后:

{
    "project_name": "Project 1",
    "project_label": "Uploaded"
}

When you want to reset everything - you must iterate over each item in the array and change set the "project_label" key to "Upload" . 当您想重置所有内容时,必须遍历数组中的每个项目并进行更改,将"project_label"键设置为"Upload"

Finally, call reloadData() . 最后,调用reloadData()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM