如何删除UITableView中的缩进? [英] How can remove indentation in UITableView?

查看:65
本文介绍了如何删除UITableView中的缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是新手,我很可能忘记了一些非常简单的东西.

First of all, I am new at this and I am most likely forgetting something very simple.

问题:

我正在制作一个在 tableView 中显示来自imgur.com的随机图像的应用程序.出于某种原因,所有单元格的缩进量都很小,如下图所示.我在 storyboard 中进行了许多设置,并且没有运气来解决此问题.

I am making an application that displays random images from imgur.com in a tableView. For some reason all of the cells are indented a small amount as seen in the picture below. I have fiddled around with many settings in storyboard and have had no luck in fixing the issue.

这是tableView代码...

Here is the tableView code...

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return (_images.count * 2);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;

if (indexPath.row % 2 == 0) {
//content cell
    cell = [tableView dequeueReusableCellWithIdentifier:@"RandomImgurTableCell"];

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

    long row = [indexPath row] / 2;

    SDImageCache* myCache = [SDImageCache sharedImageCache];
    cell.imageView.image = [myCache imageFromDiskCacheForKey:_images[row]];

}
else if (indexPath.row % 2 == 1) {
//separator cell
    cell = [tableView dequeueReusableCellWithIdentifier:@"SeparatorCell"];

    if(cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:@"SeparatorCell"];
    }
}
if (indexPath.row == (_images.count * 2) - 3) {
    [self checkToLoadMoreImages];
    NSLog(@"Hit bottom of table, getting more images");
}
return cell;
}

这是我的 tableView 和单元格设置的图片...

Here is a picture of my tableView and cell settings...

推荐答案

为了消除缩进,请将分隔符插入设置为零.结果如下图所示.

In order to get rid of the indent, you set the separator insets to zero. The result is shown in the following image.

在代码中

myTableView.separatorInset = UIEdgeInsetsZero

在界面生成器中

注释

如果单元格导致缩进,则可以将以下行添加到 tableView:cellForRowAtIndexPath :

If the cells are causing the indent, then you can add the following lines to tableView:cellForRowAtIndexPath:

cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero

如果您仍支持iOS 8之前的版本,请参见此答案以获取更多详细信息.

If you are still supporting pre iOS 8 then see this answer for more details.

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆