Reputation: 1117
I have a UIViewController with a UITableView that has custom cells inside it. The tableview creates cells correctly initially. When I scroll Down then go back up all cells disappear. my view controller is the UITableviewDelegate and UITableViewDataSource Delegate. I am implementing all required methods, namely: cellForRowAtIndexPath, numberOfRowsInSection,willDisplayCell. I am using the standard code used to display a custom tableview. Here is the tutorial I followed strictly: https://medium.com/@musawiralishah/creating-custom-uitableviewcell-using-nib-xib-files-in-xcode-9bee5824e722
My question is more abstract than technical: What causes cells to disappear upon scrolling back up? I know it has to do with cell reuse but I am using willDisplayCell to properly set content, and does the indexpath change indexes upon scrolling.\
Thanks for any clarification, hint etc.
Upvotes: 0
Views: 1387
Reputation: 12344
When the properties of cell are created and added in the method cellForRowAtIndexPath such problems occur. Create the properties in the custom class and access them after declaring custom class. For example you have a custom class named TableCell,in viewDidLoad
[yourTable registerNib:[UINib nibWithNibName:@"TableCell" bundle:nil] forCellReuseIdentifier:@"CELL"];
in cellForRowAtIndexPath
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CELL" forIndexPath:indexPath];
cell.property1 = attribute1; //property1 already created in class TableCell
Upvotes: 1