简体   繁体   中英

Xamarin iOS how to create non reusable UITableViewCells

I'm trying to create quiz answers, but because of the

var cell = (CreateMessageNewAnswerCell)TableView.DequeueReusableCell(CreateMessageNewanswerCell.Key);

I'm receiving the same box sizes from previous times. I know that the Dequeue method reuses the cells and therefore the size stays the one before, I've trying to reset the sizes but it gets itself to an unsolvable problem where the cells change places in their sizes(because of the reuse).

And therefore my question is, how do I create cells without reusing them. I have tried the following code but it didn't work

var cell = new CreateMessageNewAnswerCell(UITableViewCellStyle.Default, CreateMessageNewAnswerCell.Key);

cell.SelectionStyle = UITableViewCellSelectionStyle.None;
cell.SetModel(createMessageSession.AddAnswersModel, indexPath.Row - 1);

If you are displaying similar cells in your UITableView then I do not recommned not using cell reuse as it would negatively impact your scrolling performance and increase memory pressure.

To Handle cells of different size in one UITableView, you could use AutoLayout and set your cells height to Automatic Dimensions.

TableView.EstimatedRowHeight = 200;
TableView.RowHeight = UITableView.AutomaticDimension;

This will ensure your cells height fit their content dynamically. For more info checkout this post .

If you still do not want to use cell reuse then don't use DequeueReusableCell instead just return a new instance of your cells in the GetCell method.

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