uitableview default images showing different size? - ios

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.

Related

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 Scrolling Performance with Custom UITableViewCells

Requirement : To Display upto 9 Datapoints in a single Custom TableViewCell with 2 UILabels,4 UIButtons and 3 UIImages.
Problem Statement:Scrolling with the Custom UITableViewCell is not smooth with these UIImages and UIButtons added as subviews. There are approximately 500 rows in the UITableView.
If the problem is in number of view on one cell.
Try to set shouldRasterize property of cell's layer to YES.
yourCell.layer.shouldRasterize = YES;
yourCell.layer.rasterizationScale = [UIScreen mainScreen].scale;
But remember that all animated views such as UIActivityIndicatorView will force the cell to redraw it's content on each frame.
I use this Library which is just perfect
SDWebImage
You just need to #import <SDWebImage/UIImageView+WebCache.h> to your project, and you can define also the placeholder when image is being downloaded with just this code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier] autorelease];
}
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
cell.textLabel.text = #"My Text";
return cell;
}
It also cache downloaded images and gives you great performance.
Hope it will help you!

UIImage in TableViewCell pushes Cell Separator

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

Decreasing images in TableViewController when scrolling

I'm trying to display a UITableView with a list of artists who read from Last.fm API. I store all the artists in an array, then I show a table with your name and your picture.
Initially the photos look good, but when I do scroll the images are very small.
This is the initial appearance:
This is the appearance after scrolling, with the problem:
This is my code for create the cells:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TopArtistCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
JSCArtist *artist = self.artists[indexPath.row];
cell.textLabel.text = [artist name];
[cell.imageView setImageWithURL:[NSURL URLWithString:[[artist photo] thumbnail]] placeholderImage: [UIImage imageNamed:#"default_photo.jpeg"]];
return cell;
}
The default imageView for a UITableView acts a little odd. I would just create a custom UITableViewCell subclass and do your own layout.

Resources