user2759544
user2759544

Reputation: 181

UIImage wrong position inside table cell

I have a problem with the positioning of the elements inside a table cell. They change their position when I leaf through the table. I installed autoresizhe and indicated where they should be, but nalazeyut pictures to the text and I do not know how to fix them. I read a lot of articles but could not find a solution which is suitable for different devices. Please help me. I have text and pictures change position on their own, when I leaf through or loaded a new cell in the table. enter image description here

i add fixed size for uiimageview inside cellForRowAtIndexPath:

 [cell.imageView setFrame:CGRectMake(0,0,self.view.frame.size.width,cell.imageView.frame.size.height)];

enter image description here

enter image description here

UPDATE: i fixed my xib file. All constraints is blue. but the result is the same - bad. I do not know how to be. I suspect that the phone can not draw. enter image description here

enter image description here

Upvotes: 1

Views: 484

Answers (2)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

I assume you set the table cell height properly before you jump into any autolayout stuff

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return x;   //x is your table cell xib height
}

After you do this, LEt's go to your table cell. You provided the leading trailing top and bottom for all your elements which is good.

You dont even need to mention this in your cellForRowAtIndex method:

[cell.imageView setFrame:CGRectMake(0,0,self.view.frame.size.width,cell.imageView.frame.size.height)];

If you are trying to change the imageview frame after you set the constraints, you need to call

    [cell.imageView updateConstraints];
     [cell updateConstraints];

If you see any yellow warning in the autolayout, try to resolve it first. Xcode will suggest you some fixes for it, see that works for you ,by selecting element that has yellow warning and click on update frame option in storyboard.

See if it works!!!

Upvotes: 1

Johnykutty
Johnykutty

Reputation: 12829

Since there is a warning and you discarded that warning for constraint the frame will be reset to that shown in yellow dotted rectangle. If any warning in the auto layout constraint, fix that first then only the IB will show correct frame that will be in run time.

If you need to set dynamic cell height based on the content you have, please refer this http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout

Upvotes: 1

Related Questions