First of all, I am new at this and I am most likely forgetting something very simple.
Question:
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.
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;
}
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.
In Code
myTableView.separatorInset = UIEdgeInsetsZero
In the Interface Builder
Notes
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
If you are still supporting pre iOS 8 then see this answer for more details.
Adjusting the separator inset should fix this. I believe that the default is 15px
in from the left.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With