Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS UITableView单元';s自定义分隔符不为';不要改变它在风景上的宽度_Ios_Objective C_Uitableview - Fatal编程技术网

iOS UITableView单元';s自定义分隔符不为';不要改变它在风景上的宽度

iOS UITableView单元';s自定义分隔符不为';不要改变它在风景上的宽度,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有我的UITableView并设置了单元格的分隔符。一切似乎都很好,但我的分隔符并没有改变它在风景上的宽度。下面是它的外观: 以下是创建自定义单元格的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; ListCell *cel

我有我的UITableView并设置了单元格的分隔符。一切似乎都很好,但我的分隔符并没有改变它在风景上的宽度。下面是它的外观:

以下是创建自定义单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    ListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.backgroundColor = UIColor.clearColor;
    }
   //set cell's image and texts
   ... 


    UIView *separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, 1)];
    separatorLineView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    [cell.contentView addSubview:separatorLineView];
    [cell layoutIfNeeded];
    return cell;
}

有什么想法吗,我该如何解决这个问题?

在ListCell.h中添加分隔符行属性-

@property (strong, nonatomic)  UIView *separatorLineView;
尝试用以下代码替换分隔符行的代码-

int screenHeight;
if ( [[UIApplication sharedApplication] statusBarOrientation] != UIInterfaceOrientationPortrait
    &&  [[UIApplication sharedApplication ]statusBarOrientation] != UIInterfaceOrientationPortraitUpsideDown){
    screenHeight = [UIScreen mainScreen].applicationFrame.size.width;
} else {

    screenHeight = [UIScreen mainScreen].applicationFrame.size.height;
}

if(cell.separatorLineView.superview == NULL){
     cell.separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenHeight, 1)];
    cell.separatorLineView.backgroundColor = [UIColor colorWithHue:0 saturation:0 brightness:0 alpha:0.1];
    [cell.contentView addSubview:cell.separatorLineView];
    [cell layoutIfNeeded];
}
我一定会工作的

或者您可以通过情节提要添加分隔线-


您还没有告诉视图如何调整大小……谢谢,它成功了!还有一个问题发生了——当我在表格中滚动时,是否有可能每次都在同一行上反复绘制单元格的分隔符?每次分隔符比最初设置的更粗时,它都不会画线,并给我这个错误——将保留对象指定给弱属性;任务完成后对象将被释放好的,我已经用故事板完成了。非常感谢你