Lia*_*and 5 iphone objective-c uitableview ios
首先,我是新手,我很可能会忘记一些非常简单的事情.
题:
我正在制作一个应用程序,显示来自imgur.com的随机图像tableView.由于某些原因,所有单元格都缩进了一小部分,如下图所示.我已经摆弄了许多设置storyboard并且没有运气来修复问题.

这是tableView代码......
- (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;
}
Run Code Online (Sandbox Code Playgroud)
这是我tableView和细胞设置的图片......

为了摆脱缩进,您将分隔符insets设置为零.结果如下图所示.
在代码中
myTableView.separatorInset = UIEdgeInsetsZero
Run Code Online (Sandbox Code Playgroud)
在Interface Builder中
笔记
如果单元格导致缩进,则可以将以下行添加到tableView:cellForRowAtIndexPath:
cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero
Run Code Online (Sandbox Code Playgroud)
如果您仍然支持iOS 8之前,请查看此答案以获取更多详细信息.
| 归档时间: |
|
| 查看次数: |
8505 次 |
| 最近记录: |