Repeat using UITableViewCell (custom height for each) in a Twitter-like client

I am working on a project, for example, with the iOS version for the Twitter client. When designing a tabular view, each cell changes its height to place its contents (tweet).

But I ran into a problem: the current height of the screen cell works well, but when scrolling down, the new cell reuses the height of the old cells.

+4
source share
1 answer

Yes, table programming is what the model-view-controller approach really suits. If you change the height of your cell somewhere like tableView:didDeselectRowAtIndexPath: you may feel that it works, but it doesn’t. What you can do in this method is to change your data and reload the table (or part of it).

As mentioned above, you must:

Specify the correct height for each cell in

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

Specify the correct view (cell) in

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

When you want to make some changes, you must change your data in model (or the corresponding object containing your data related to the content), and then call one of the UITableView reload methods, perhaps:

 - (void)reloadData - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

Apple's documentation can be scarce (although I think it's pretty professional): These will be the main links for you:

UITableView Class Reference

Link to UITableViewDataSource Protocol

Link to UITableViewDelegate Protocol

Table Programming Guide for iOS

+3
source

Source: https://habr.com/ru/post/1398320/


All Articles