Can I call tableViewcellForRowAtIndexPathtableView in heightForRowAtIndexPath to find cell’s size?
Is it too expensive in terms of performance, if not how else can I find cells height if it comes from XIB?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t do this. It won’t work anyway.
tableView:heightForRowAtIndexPath:is called for all of your cells. AndcellForRowAtIndexPath:won’t return cells for the non visible indexPaths anyway.When
tableView:heightForRowAtIndexPath:is called the first time (just afternumberOfSectionsInTableView:andtableView:numberOfRowsInSection:) there is no cell at all.Just check the height of the cell in interface builder. Select the UITableViewCell view and look into the size panel.
Because
tableView:heightForRowAtIndexPath:is called for every cell you should set the height of the cells in viewDidLoad if you only have one height. IftableView:heightForRowAtIndexPath:is not implemented it is not called, which is great if you have many cells.If you have different heights, figure out the height from your dataSource. E.g. check the object at the indexPath from your dataSource NSArray and use the same logic you use in
tableView:cellForRowAtIndexPath:to figure out which cell to use. Then return the appropriate height.EDIT: I just tested it and querying the tableView for a cell in
tableView:heightForRowAtIndexPath:causes an infinite loop.