【发布时间】:2016-06-19 04:22:32
【问题描述】:
我在 UITableViewCell 中有一个标签,我希望我的高度 TableViewCell 根据标签高度是自动的。
- (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
}
【问题讨论】:
-
你在使用自动布局???
-
不仅仅是在 heightForRowAtIndexPath 中返回
UITableViewAutomaticDimension.. 但条件是您的约束应该正确附加
标签: objective-c iphone autolayout uitableview