无法在UI表视图自定义单元格中创建分隔符插件

时间:2016-03-23 11:00:03

标签: ios swift uitableview

我试图从左右两侧制作20 pt插页的分隔符。 无论我做什么,我仍然从一个边缘到另一个边缘得到一条完整的线条。

我尝试过的: 在属性检查器中,选择分隔符 - 自定义插入并从左右添加20像素。

我也试过if(data && data.people.length > 0){ // If i have some response form serve var tmp = {}; var lastName = null; for(var i = 0; i < data.people.length; i++){ if(ppl.lastName != lastName){ if (lastName != null){ $scope.people.push(tmp); } // Clean the tmp tmp = { name : null, count : 0, products : [] }; // Update lastName lastName = ppl.lastName; } // Add the actual row in the ob tmp.name = lastName; tmp.count += ppl.personCount; tmp.products.push(ppl); }; // Process lasts elements (if there are some) in the array if (tmp && tmp.products && tmp.products.length > 0) $scope.people.push(tmp); } } -

viewDidLoad

我仍然得到一个完整的线.. 任何帮助将不胜感激 感谢

2 个答案:

答案 0 :(得分:0)

setSeparatorInset中的willDisplayCell

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
           [cell setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
    }
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 20, 0, 20)];
    }
}

参考:iOS 8 UITableView separator inset 0 not working

答案 1 :(得分:0)

您也可以在界面构建器中设置分隔符插入

转到属性检查器,您可以在分隔符插入下更改为您想要的值