Cyclic loading of custom cells Swift

给你一囗甜甜゛ 提交于 2019-12-11 14:55:12

问题


I've been trying to get some response from stack on this issue for a while now with no success.

So i will try to be very precise.

I have an uitableview with two custom cell nibs. Data source for both are two separate arrays (questions array and answers array). The first custom cell contains uilabel (question cell) and another one uibutton (answer cell).

On launch of the app a specific amount of question cells load up (depending on the amount of objects in the array) and after them the 1 answer cell loads up.

Here is the pic

after click answer2 - again the same procedure happens producing new question cells below as well as the answer3 cell

Don't know how to achieve that.

Thank you!


回答1:


This is not that hard as it seems. So, on the launch of the app, you load the initial questions and answers. For that you would need the number of required cells, say, 3 questions and 1 answer, totally you need to return 4 from the numberOfCellsInSection:. And, when the user taps(selects, press) the answer row, you just increase the number of cells on the table, if you have 2 questions and 1 answer on the next cycle, now you would return 7 from the numberOfCellsInSection: datasource method of the tableView. And so on.

Also, you can divide the each question-answer into the sections, if you want to have more organized way of achieving your goal. In this case, you have to increase the number of sections in the table, and return proper number of cells for each section on answer cell selection. Use numberOfSectionsInTableview: and numberOfCellsInSection methods of the datasource for this.

Don't forget to draw (set proper texts to the cell's labels, image if any) the data on cellForRowAtIndexPath: method to reflect the correct data on your cells.



来源:https://stackoverflow.com/questions/32283593/cyclic-loading-of-custom-cells-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!