简体   繁体   English

快速以编程方式添加不同数量的标签和滑块

[英]Adding varying numbers of labels and sliders programmatically in swift

In swift and Xcode I want to be able to make an app where the user can enter what subjects they have, and then proceed to the next page, where they are greeted with a page where they can pick how much they like each subject as a percentage, using labels and sliders. 在swift和Xcode中,我希望能够制作一个应用程序,使用户可以输入他们拥有的主题,然后进入下一页,在该页面上迎接他们可以选择自己喜欢的主题的页面。百分比,使用标签和滑块。

What I am unsure about is how I can add varying amounts of labels and sliders, depending on how many subjects they add. 我不确定的是如何根据标签添加的数量添加不同数量的标签和滑块。

eg if the user inputs Maths, English, and Science, on the next page, I will need to add exactly 3 labels and exactly 3 sliders programmatically. 例如,如果用户在下一页输入数学,英语和科学,则需要以编程方式添加恰好 3个标签和恰好3个滑块。

If anyone could tell me how I would go about solving this problem I would much appreciate it :) 如果有人能告诉我如何解决这个问题,我将不胜感激:)

In the first page, where the user 'picks' the subject, add these subjects to an array object. 在用户“拾取”主题的第一页中,将这些主题添加到数组对象中。 The array object will then have a count. 数组对象将具有一个计数。

On the second page, pass through the array of 'subject' object inside of an array. 在第二页上,在数组内部传递“主题”对象的数组。 Then add a UITableView to the second page. 然后将UITableView添加到第二页。 Make a prototype UITableViewCell that contains a UILabel and a UISlider. 制作一个包含UILabel和UISlider的原型UITableViewCell。 Then on the UITableViewDelegate and Datasource, set the numRowsForSection to be the count of the array, and the table will draw that many cells. 然后在UITableViewDelegate和Datasource上,将numRowsForSection设置为数组的计数,该表将绘制那么多单元格。 Then pass the subject data from the array to the cell with cellForRowAtIndexPath and continue from there. 然后使用cellForRowAtIndexPath将主题数据从数组传递到单元格,然后从那里继续。

If you are not familiar with UITableView and its delegate/datasources, look those up first! 如果您不熟悉UITableView及其委托/数据源,请先查找它们!

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

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