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.
Related
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;
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];
}
I have a customized UITableViewCell and I've added a UIImageView to it. The thing is, there are times when I want to remove the UIImageView as the data I receive from the server does not have an image associated with it. How do I make the cell layout change such that the other elements move up. Should I set the UIImageView's frame to zero? Using a placeholder image is not a solution.
Here's what my problem looks like:
The row with index 0 does not have an image but there is a space in between the top and the bottom label. Is there a way I can do this using Auto Layout?
Your problem is actually caused by heightForRowAtIndexPath, you have to return the proper value in this method, something like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
YourCustomObject *object = [tableDataSource objectAtIndex:indexPath.row];
if(object.hasImage) {
return heightForCellWithImageInside;
}
else {
return heightForCellWithoutImageInside;
}
}
Then, in your cellForRowAtIndexPath just hide the UIImageView if there is no image for it.
You can dynamically change the height of cell.If there is an image,then increase cell height otherwise not.Also set the imageView whenever u get image from server otherwise no need to set imageView.like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"ImageCellItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if(imageFromserver)
{
//Set your imageView here
}
else
{
// Do nothing
}
return cell;
}
when ever there is no image coming from server hide or remove your image view and assign the frame of image view to your bottom label.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
}
if(yourimage==nil)
{
bottomlabel.frame=imageview.frame; // you can do something like this, as per your need.this is just example
}
return cell;
I have a custom leaderboard which I load Game Center profile pictures into a UITableCell that is 32 high.
What happens is when I set the image it displays at around 200x32 then quickly resizes to be a square. The user sees a flash where the image is distorted before it is shown properly.
What is happening here? How can I fix this?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([GCCustomLeaderboard sharedInstance]->nearbyScores.count == 0){
return nil;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyBasicCell"];
GCLeaderboardScore *playerScore = [[GCCustomLeaderboard sharedInstance]->nearbyScores objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:#"%#: (%d)", playerScore->alias, (int)playerScore->score];
cell.imageView.image = playerScore->photo;
return cell;
}
To fix this I had to resize my images BEFORE putting them in the table.
I am working in a iPad application. I'm using a UITableView to create a table and insert 2 UIImageViews in each cell. I tried to set image in both UIImageViews, but index path values start from 0,1,2,3,4 etc...
Each UIImageView has same image in first cell. How to fix this issue?
Example:
- (void)viewDidLoad
{
[super viewDidLoad];
// ImageArray have 5images;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [ImageArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
imgView1.image = [imageArray objectAtIndex:indexPath.row];
imgView2.image = [imageArray objectAtIndex:indexPath.row];
}
After formatting your code it becomes clear that you are assigning the same image from the array to each of the two image views. You will need an imageViewArray that has the double amount of members.
Also, you should not check for the count of your image array but for the row of your index path.