I would like to create a custom height UITableViewCell using (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
I am trying to get the height UITableViewCellby multiplying the number of lines in textLabelby the height of each line and then adding 10.0ffor subtitles. I use the following code and get exc_bad_access(). Why?
UITableViewCell
textLabel
10.0f
exc_bad_access()
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return ([[[tableView cellForRowAtIndexPath:indexPath] textLabel] numberOfLines] * [[[[tableView cellForRowAtIndexPath:indexPath] textLabel] font] lineHeight]) + 10.0; //return kRowHeightiPod; //A constant value for a sanity check }
Before you can get a cell, you need to calculate its height. You just calculated its height, depending on the receipt of the cell. You have created infinite recursion.
, , , , , .
, numberOfLines , , , . , , numberOfLines , , .
numberOfLines
, NSString UIKit , .
? , , , ...
, - - textLabel. NSZombieEnabled YES , , ...
Source: https://habr.com/ru/post/1767964/More articles:Decode sha1 string to regular string - iphoneWCF Security in Internet Scenarios - securityStrict string in byte encoding in C # - c #Force update NSFetchedResultsController when changing the number of associations - iphoneHow to make VS Unit Test show an error message from exceptions other than UnitTestAssertException? - exceptionThe type of a pointer to an element from the base class - c ++css showing images twice opposing one? - javascriptBrowser behavior with huge doms - optimizationCustom icon does not appear in the upper left corner or on the taskbar - c ++Python 2.7 AES compatible AES encryption library - pythonAll Articles