I am having an app in which I have a Tableview and on that tableview\'s each row I am dynamically creating a custom tableview cell.
Below is the cod
Here we go:
UITableViewCell
subclass for all the cells in your view (such as FlowViewAbstractTableViewCell
)+ (CGFloat)sizeForCellWithComment:(Comment *)comment
. What you're doing is setting up a method to pass a model object into that each table view cell subclass can implement.FlowViewAbstractTableViewCell
. In your case, it looks like you could have ones called FlowViewTextCommentTableViewCell
and FlowViewPictureCommentTableViewCell
.+sizeForCellWithComment:
method. This will allow you to return a variable size based on the object you pass into the method.- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
for your UITableViewDelegate
. In this method you are going to figure out which cell class you want to use and which object to pass into that size method. For example:- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
Comment *commentForCell = [self.comments objectAtIndex:indexPath.row];
return [CommentTableViewCell sizeForComment:commentForCell].height;
}
This will allow you to return a variable cell height based on the object. I use variably sized table view cells all the time & love this pattern because I think it does the best job of hiding the implementation and following MVC.