Adding a view (image view) in between two UITableV

2020-04-21 01:32发布

问题:

I have created a UITableView programatically. And i am loading it with data. I want to insert an advertisement Banner (clickable button which is equal to cell's height and width) into this table view after every 4 rows. Is it possible to insert that ? or should i add something to array which i am loading the table view with ?

Thanks in advance.

回答1:

No, it's not possible. The table view owns its whole area, and renders cells based on it's internal logic.

You could divide your table view into sections and add a custom cell as a section header or footer, or you could make your cellForRowAtIndexPath serve up a custom type of cell for every 4th row that ONLY contains your full-sized button. That should accomplish your goal.



回答2:

As Duncan mentioned you could use cellForRowAtIndexPath and place a custom cell type for every 4th row. You can set two types of custom cells in your tableview by setting the identifier property. Ex. For every 4th row use the "ad" identifier cell.