UIImage in TableViewCell pushes Cell Separator - ios

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.
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.

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.

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;
}

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];
}

Related

Why the UITableViewCell changed its size when I slide the view

I am a beginner in iOS development. I face a problem where I need little help.
I wrote a small program to learn custom UITableViewCell. It just works well at beginning; after that, when I slide the view, it changes size of the cell. I am confused about where I might be going wrong. The ContentView have only one view which is UIImageView.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HWHomePageCell"];
if (cell == nil)
{
cell = [HWHomePageCell homePageCell];
}
cell.imageView.image = [UIImage imageNamed:#"XD"];
return cell;
}
These are the pictures. Top two are good, but when I slide down, as you can see, the 3rd doesn't work well
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HWHomePageCell *cell = [tableView dequeueReusableCellWithIdentifier:#"HWHomePageCell"];
cell = [HWHomePageCell homePageCell];
cell.imageView.image = [UIImage imageNamed:#"XD"];
return cell;
}
When you use custom cell then no need to check whether cell is nil or not. so please remove this condition and implement it.
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;

how to make Dynamically Cell size Adjustment According to UIlabel text size

I am Beginner to iOS, I was facing problem , How to make Custom Cell size is Adjusted to UILabel Size of text. also I cant display Long Dynamically text in UILabel Fully, its show only selected Rows, it displays only selected line in Attribute inspector that much it will displays. how to fix this both problem. help me
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [_data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
SingleTableViewCell *cell = (SingleTableViewCell *)[_mytable dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[SingleTableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier];
}
cell.labelTitle.text=[_data objectAtIndex:indexPath.row];
cell.labelcount.text=[NSString stringWithFormat:#"%u", (arc4random() % 74)];
return cell;
}
This my Table delegate code. I saw my CGrect for calculate text size etc, but i will not work here.
I am using Xcode 6.1.1, and Objective-c .
You can use Autolayout and set the borders of the label to the cell then in your viewDidLoad method do this:
self.tableView.estimatedRowHeight = 44; // or your default size
self.tableView.rowHeight = UITableViewAutomaticDimension;

Reasons for UITableViewCell UI inconsistency

Most of the time, when my app is working the way it should, my Table View items look like this:
But every so often a cell (on initial load) looks likes this:
As you can see the image has resized, the 'published By' label has resized.
Why would this happen? The same code/storyboard should affect all the cells the same way? Why are some not doing what they are told?
If it helps, when a cell loads the wrong way, all I have to do is scroll up, and back down again, and the problem is fixed !!
This means that there clearly isn't a problem with the image or the amount of text, is it just the iPhone acting up?
Thanks for any help !
I think its cell dequeue issue. Your cell could not calculate proper height for cell. If you are using autolayout try the following code. hope it will works for you.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
static YOUR_TABLEVIEW_CELL *sizingCell = nil;
static NSString *CellIdentifier=#"YOUR_TABLEVIEW_CELL_IDENTIFIER";
sizingCell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (sizingCell==nil)
{
sizingCell=[[YOUR_TABLEVIEW_CELL alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[self configureFareIssueCell:sizingCell atIndexPath:indexPath];
return [self calculateHeightForConfiguredSizingCell:sizingCell];
}
//assign all the lables & images here
- (void)configureFareIssueCell:(YOUR_TABLEVIEW_CELL* )cell atIndexPath:(NSIndexPath *)indexPath
{
//e.g
cell.lbl.text=#"YOUR_TEXT";
cell.imageView.image=[UIImage imageNamed:#"NAME_OF_YOUR_IMAGE"];
}
- (CGFloat)calculateHeightForConfiguredSizingCell:(YOUR_TABLEVIEW_CELL *)sizingCell
{
CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height + 1.0f; // Add 1.0f for the cell separator height
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=#"YOUR_TABLEVIEW_CELL_IDENTIFIER";
YOUR_TABLEVIEW_CELL *cell =[tableView dequeueReusableCellWithIdentifier:#"YOUR_TABLEVIEW_CELL_IDENTIFIER"];
if (cell==nil)
{
cell=[[YOUR_TABLEVIEW_CELL alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[self configureFareIssueCell:cell atIndexPath:indexPath];
return cell;
}
Do you use layer mask for creating rounded image? If yes, you see this strange behavior because layer mask was created before UITableView assign proper frame for cell, so layer mask will have incorrect frame.

UITableView Image in the Cell Shrinks

The images in the tableview cell shrinks as soon as they are scrolled. They resize to the wanted size by reload.
The big stars have the size I want. The smaller ones appears during scrolling or on touch.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"Cell";
NSArray *sectionData = self.dataSource[indexPath.section];
SHFriendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
[cell updateWithData:sectionData[indexPath.row]];
return cell;
}
- (void)updateWithData:(SHFriendTableCellData *)data {
self.friendImage.contentMode = UIViewContentModeScaleToFill;
self.friendImage.image = data.image;
self.nameLabel.text = data.name;
}
Changing the content mode has no effect.
I had a double reference to the image view.
After deleting the issue was gone after I deleted the double reference.

uitableview default images showing different size?

Hi I have one UItableView with images,title and description
When i run the app i can see the images are showing as large size but if i click that row then images become small(original size ).
May i know why this happening?
code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
offerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.offerImage.layer.masksToBounds=YES;
cell.offerImage.layer.cornerRadius=9.0;
cell.backgroundColor=[UIColor clearColor];
if([offertitle count]>0){
// Configure the cell...
NSLog(#"%#",backupImage);
[cell.offerImage setImageWithURL:[NSURL URLWithString:[backupImage objectAtIndex:indexPath.row]]placeholderImage:[UIImage imageNamed:#"Placeholder.png"]]
;
cell.offerTitle.text=[offertitle objectAtIndex:indexPath.row];
cell.offerDetails.text=[offerDetails objectAtIndex:indexPath.row];
}
// cell.websiteImage.image=[imageArray objectAtIndex:indexPath.row];
return cell;
}
In UitableViewCell, the default image frame will be change based on setting UIImage. I means if you set tableview height as 50, so by default the Default Cell UIImageView height 50. so based on height imageview width will be change for displaying the image without blur.
so you have to take all images are at same size, or You have to create custom UIImageView in place of cell default UIImageview.

Resources