【问题标题】:Tableview word wrap works in Simulator, but not on deviceTableview 自动换行在模拟器中有效,但在设备上无效
【发布时间】:2015-06-27 14:33:01
【问题描述】:

以下代码在 8.3 模拟器上按预期换行为多行;但在 8.3 iPhone 6 上运行时会截断该行。????

代码如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *simpleTableIdentifier = @"Active Playlist";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

     cell.textLabel.numberOfLines = 0;
     cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;

    cell.textLabel.text = [playList objectAtIndex:indexPath.row];
    return cell;
}

【问题讨论】:

    标签: ios objective-c iphone ios-simulator tableview


    【解决方案1】:

    您是否尝试过将两个负责的 lignes 放入 if 语句中,以便仅在启动单元格时调用它们?

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
    }
    

    【讨论】:

    • 根据您的建议;我尝试过这个;没有区别!
    • 它的工作原理是指定字体大小;例如:[[cell textLabel] setFont:[UIFont systemFontOfSize: 14.0]]; (但是,字体大小为 23 失败),因此,它一定与高度有关 - 但是 - 这仍然引出了一个问题,即为什么它在 IB 中设置的字体在模拟器中工作正常,而不是在设备中工作正常。
    • 我的下一个猜测是设置字体。有时设备的行为和模拟器的行为之间的差异真的很奇怪,但通常是模拟器停止工作而不是设备......你尝试过(动态和)不同的单元格/文本标签高度吗?跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多