I have a label in the UITableViewCell, and I want my height TableViewCell is auto according label height.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TWTTweetTableViewCell *cell = (TWTTweetTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"TWTTweetTableViewCell" forIndexPath:indexPath];TWTTweet *tweet = self.tweets[indexPath.row]; cell.tweetMessage.text = tweet.tweetMessage; cell.timestamp.text = [tweet howLongAgo]; cell.tag = indexPath.row; TWTUser *user = [[TWTTwitterAPI sharedInstance] userForId:tweet.userId]; cell.user.text = user.username; return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 165; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //Tapped a tweet }
UITableViewAutomaticDimension
in heightForRowAtIndexPath .. but condition is your constraints should attached properly – EI Captain v2.0