【问题标题】:Why tableview cell text not changed according to orientation, while cell height did为什么表格视图单元格文本没有根据方向改变,而单元格高度却没有
【发布时间】:2013-11-04 12:46:29
【问题描述】:

我的代码如下,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Color Cell" forIndexPath:indexPath];    
    ......
    ......
    ......

    if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:14.0f];
    } else {
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:24.0f];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat rowHeight;
    if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
        rowHeight = ([[UIScreen mainScreen] bounds].size.width - 52) / [colorArray count];
    } else {
        rowHeight = ([[UIScreen mainScreen] bounds].size.height - 64) / [colorArray count];
    }
    return rowHeight;
}

运行它时,表格视图可以正确地自动重新定向,单元格高度也是如此。但单元格文本大小不会相应改变。

为什么?如何解决?

左边是纵向,右边是横向

【问题讨论】:

  • 字体似乎变小了。我认为横向模式下单元格高度和字体大小的比例不正确。只是进一步减小字体大小。
  • 不,纵向和横向的文本大小完全相同,不会根据方向改变。只有单元格高度可以。我添加了比较快照。
  • 您在 IB 中设置了最小字体大小吗?
  • 试过了,甚至设置的最小尺寸(9 pt)比代码中设置的尺寸(14)更小。但什么都没有改变。

标签: ios uitableview uiinterfaceorientation landscape-portrait


【解决方案1】:

UITableViewCell在设备中更改方向时不重新加载,更改方向后重新加载表格视图

【讨论】:

  • 你的意思是self.tableView reloadData 吗?放在哪里?
  • 在改变方向时添加self.tableView reloadData。
  • 添加到viewDidLoad(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,或其他?
  • -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if(port right) { //reload action; } else { //重新加载动作; } }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多