简体   繁体   中英

How to hide and unhide a imageview in a tableview cell?

I am using a tableview with two rows. Each row having a Label, Button and Image View .Initially the the row height is 50 with no image. When I click the Button in the cell the Image Picker will open and select a image from camera roll. So how can I update the tableview height to 100 with a Image View in cell?

You can achieve this using autolayout. If you design your cell like this in a xib :

Cell for height 100 : 在此处输入图片说明

With these constraints on the image view :

在此处输入图片说明

It will look like this with height 50 :

在此处输入图片说明

The weird line is the image view that got automatically shrunk by autolayout. It looks bad in interface builder, but will be ok on the device/simulator. The one thing you have to remember about is to simply remove the image (not the image view!) when the cell is at 50 height and set it when it is at 100.

Also I'd recommend you to learn about autolayout as it is a powerful tool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM