简体   繁体   English

滑动以删除将UITableViewCell移动到左侧

[英]Swipe to delete moves the UITableViewCell to the left

I use custom code to create cells that get displayed on a UITableView. 我使用自定义代码来创建在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. UIView属性autoresizingMask允许您指定子视图在其autoresizingMask视图(在本例中为UITableViewCellcontentView )调整大小时的行为方式。

See the View Programming Guide for iOS for more information. 有关更多信息,请参阅适用于iOSView Programming Guide

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

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: 另一方面,如果您希望视图在单元格中发生其他任何事情时保持完整,则必须将内容添加为单元格contentView的子视图:

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

I do hope this helps. 我希望这会有所帮助。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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