简体   繁体   中英

Swipe to delete moves the UITableViewCell to the left

I use custom code to create cells that get displayed on a UITableView. When a row is swiped, the delete button appears on the far right of the cell as expected. However it causes the contents of the cell to move to the left (partly off screen). This kind of behaviour didn't happen when using the cells that are built in to the framework.

The UIView property autoresizingMask allows you to specify how your subviews should behave when their superview (in this case the UITableViewCell 's contentView ) gets resized.

See the View Programming Guide for iOS for more information.

是不是因为你的内容受到了正确的限制?

Although this answer may be too late, I believe the problem is due to the fact that you happen to be adding your content directly to the cell by writing something like:

MyView* myView = [[MyView alloc] init];
[cell addSubview : myView];

This happens to be good; however, your content will be affected by any change that takes place within the cell. If, on the other hand, you want your views to remain intact while anything else happens to the cell, you must add your content as subviews of the cell's contentView:

MyView* myView = [[MyView alloc] init];
[[cell contentView] addSubview : myView];

I do hope this helps.

Cheers!

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