代码之家  ›  专栏  ›  技术社区  ›  amitsbajaj

右侧详细信息UITableViewCell在iPad上未显示全行

  •  0
  • amitsbajaj  · 技术社区  · 10 年前

    大家节日快乐!

    我有一个带有UITableViewController和多个部分的简单应用程序。节0正在使用基本UITableViewStyle,节1正在使用右详细信息UITableViewStyle。仅在iPad上,我面临着一个非常奇怪的问题,即第1节中的UITableView的线条不会一直延伸到设备的末尾,如下图所示:

    enter image description here

    顶部是section 0,基本UITableViewStyle,底部是Right Detail UITableViewStyle。

    这是预期的行为,是一个错误(最新的Xcode和iOS 9.2),还是有一个简单的修复方法?

    请注意,这只是一个iPad的问题,因为它在iPhone(包括6 Plus)上看起来很好,在模拟器和iPad Air 2设备上也是一样的。

    对此有任何想法将不胜感激。

    更新:

    我在这个类中的代码:

    - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        // Custom label for the section header titles
        UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, self.moreTabTableView.frame.size.width, 10)];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        [label setFont:[UIFont systemFontOfSize:15.0]];
    
        if (section == 0)
        {
            label.text = @"Show Your Support";
        }
        else if (section == 1)
        {
            label.text = @"Connect with the BOS Team";
        }
        return label;
    }
    

    它都是在Storyboard中创建的,因此这是该类的唯一代码。

    使现代化

    我又看了一遍我的代码,看看这是怎么回事。我正在为UITableViewCell使用一个自定义类(称为CustomMoreTableViewCel),我只在该自定义子类中有此代码:

    - (void)layoutSubviews
    {
        self.imageView.frame = CGRectMake(8, 8, 30, 30);
        self.textLabel.frame = CGRectMake(47, 11, 300, 21);
    }
    

    我正在确保图像的大小适合每个单元格。我刚刚将Donate单元格设置为自定义UITableViewCell子类,它在缩短行数方面做了同样的事情。

    我能够通过使用自定义UITableViewView子类来重现这一点,但我不确定需要什么才能使这些行一直运行下去(我已经尝试了大量imageView和textLabel的值)。

    1 回复  |  直到 10 年前
        1
  •  1
  •   matt    10 年前

    更改您的 layoutSubviews 实现如下:

    - (void)layoutSubviews
    {
        [super layoutSubviews];
        self.imageView.frame = CGRectMake(8, 8, 30, 30);
        self.textLabel.frame = CGRectMake(47, 11, 300, 21);
        self.separatorInset = UIEdgeInsetsZero;
    }
    

    如果结果不完全符合您的要求,则调整 separatorInset 照着

    (不过,最好的方法是使用一个完全自定义的单元格,而不是像现在这样尝试修改现有的内置单元格样式。)