I am using UITableViewController
instead detailView to show one entity details. I populated one row of data from PFQuery in my viewDidLoad
method. I have one cell where I am using label, I want to change the size as per NSString
size. I checked a lot of answers but all are related to indexPath
which is for dynamic and I have static cells. My label
showing complete string, but my cell is fixed. How can I change the height of the cell? Please help me to correct this problem.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
PFQuery *query = [PFQuery queryWithClassName:@"Entities"];
[query whereKey:@"name" equalTo:entityName];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
PFFile *thumbnail = [objects[0] objectForKey:@"image"];
detailsImageView.image = [UIImage imageNamed:@"loader.gif"];
detailsImageView.file = thumbnail;
[detailsImageView loadInBackground];
detailLabel.numberOfLines = 0; // this label need dynamic height and its cell
detailLabel.text = [objects[0] objectForKey:@"descriptionLarge"];
[detailLabel sizeToFit];
} else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
NSLog(@"Error: %@", errorString);
}
}];
}
I am trying to do the following by selecting individual cells but it gave me UITableView error as I have not define tableView, how can I define or if you have any other good solution please let me know.
static NSString *simpleTableIdentifier = @"DetailsDesecriptionCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
I am also open on criticism of about coding quality so your feedback is valuable for me.
To get dynamic cell heights working properly, you need to create a custom table view cell and set it up with the right Auto Layout constraints. In the project navigator, select the Views group and press Command-N to create a new file in this group.
Set your view controller constraints in the Storyboard and then create an outlet to the UITableView height constraint in your UIViewController subclass (or the constraint that controls the height of the UITableView like the distance to the bottom of the screen).
If it is IOS 8 OR 9, there is a simple fix.
tableView.estimatedRowHeight = 68.0 tableView.rowHeight = UITableViewAutomaticDimension
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With