0

I've added a UIImage to my table view cell. However, the UIImage is pushing the separator over to the right to make room for the UIImage. I'd like to find a way to have the separator include the UIImage and not be pushed over. Here is a picture of my table view cell.

enter image description here

Here is my cellForRowAtIndexPath method with code for the image:

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

    UITableViewCell *cell =
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier
                                forIndexPath:indexPath];

   Exercise *tempPlaceholder = [exercisesInTable objectAtIndex:indexPath.row];



   NSString *exerciseDisplayName = tempPlaceholder.exerciseName;

   exerciseDisplayName = [exerciseDisplayName capitalizedString];

    exerciseDisplayName =
   [exerciseDisplayName  stringByReplacingOccurrencesOfString:@"_"
                                                withString:@" "];

   cell.textLabel.text = exerciseDisplayName;

   cell.imageView.image = [UIImage imageNamed:@"quads.png"];


    return cell;
}

If anyone could help me with this I'd really appreciate it. Thank you.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
zic10
  • 2,310
  • 5
  • 30
  • 55
  • 1
    Look at this http://stackoverflow.com/questions/18365049/is-there-a-way-to-make-uitableview-cells-in-ios-7-not-have-a-line-break-in-the-s – Infinity Feb 16 '14 at 20:30

3 Answers3

1

For anyone else who runs into this problem, using:

[self.tableView setSeparatorInset:UIEdgeInsetsZero];

will fill the gap between the UIImage and the table cell separator.

zic10
  • 2,310
  • 5
  • 30
  • 55
0

Try change the size of imageView frame

cell.imageView.frame = CGRectMake(0, 0, 10.0, 10.0);

Or change the height of cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  return 40.0;
}
Jaroslav
  • 1,863
  • 1
  • 12
  • 10
0

The behaviour you are experiencing will only occur on iOS 7 where the separators have insets that by default change with image view size.

To remove this behaviour simply set the separator insets to zero. However the separatorInset property is available on UITableView from iOS 7.0

So you only have to remove the inset in iOS 7.

You can check whether the table view responds to setSeparatorInset: doing

if ([self.tableview respondsToSelector:@selector(setSeparatorInset:)]) 
{
    [self.tableview setSeparatorInset:UIEdgeInsetsZero];
}
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143