简体   繁体   中英

Cyclic loading of custom cells Swift

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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