現在、Json を介して Twitter フィードを取得しており、ツイートの長さを取得する前に heightForRowAtIndexPath が呼び出されています。したがって、heightForRowAtIndexPath が読み込まれると、fullTweet.length は常にゼロになります。このhttp://gyazo.com/632d09685268e1737d3c58bf1718cbff.pngのようにセルのサイズを変更しようとしているので、余分な空白を無駄にしません。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(fullTweet.length >= 50) {
return 50.0f;
} else
return 92.0f;
}
私の方法の仕組み
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TweetCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
NSString *text = [tweet objectForKey:@"text"];
cell.textLabel.text = text;
fullTweet = text;
NSLog(@"%i", fullTweet.length);
cell.textLabel.numberOfLines = 3;
return cell;
}
何か案は ?