简体   繁体   English

附件视图显示单元格的一半

[英]Accessory View Is Showing Up Half Off of the Cell

I cant figure out how to get my accessory view to fit into my cell. 我不知道如何使附件视图适合我的单元格。 Also, When I add a subview it adds it to the right of the first subview added. 另外,当我添加一个子视图时,它会添加到添加的第一个子视图的右侧。 I want the sub views to be added from right to left. 我希望从右到左添加子视图。

I have this for my accessory view 我的附件视图有这个

UIView *myAccessoryView = [[UIView alloc] initWithFrame:cell.accessoryView.frame];

And anytime I add a sub view I just write this 每当我添加一个子视图时,我都会这样写

[myAccessoryView addSubview:greenCircle];

And as soon as it adds another subview it is placed to the right of the previous sub view which is even further off my cell. 并且,一旦添加了另一个子视图,它就会被放置在离我的单元格更远的前一个子视图的右侧。 How do I reverse the way it adds subview? 如何反转添加子视图的方式? How can I format the accessory view to stay on the cell? 如何格式化附件视图以保留在单元格上?

You are trying to init myAccessoryView with the frame of accessoryView that doesn't yet exist. 您正在尝试使用尚不存在的annexView框架来初始化myAccessoryView。 It will be created after cell creation (and adding to tableView) if you specify cell.accessoryType property, or if you create and set accessoryView yourself like: 如果您指定cell.accessoryType属性,或者您自己创建并设置了附件视图,则将在创建单元格(并将其添加到tableView)之后创建它:

[cell setAccessoryView:myAccessoryView];

So if You do this: 因此,如果您这样做:

UIView *myAccessoryView = [[UIView alloc] initWithFrame:cell.accessoryView.frame];
[cell setAccessoryView:myAccessoryView];

You will have accessoryView with zero size and coordinates. 您将获得具有零尺寸和坐标的附件视图。 After the cell is set to tableView, accessoryView will get standart origin point in the right side of the cell. 将单元格设置为tableView后,accessoryView将在单元格的右侧获取标准起点。 But it still have zero size. 但是它仍然具有零大小。 And all subviews You add to accessoryView will be set to that origin point. 并且您添加到annexView的所有子视图都将设置为该原点。

Method "addSubview" cant change subviews frame, it just places one view to another view. 方法“ addSubview”不能更改子视图框架,它只是将一个视图放置到另一个视图。 Have no ideas why new subviews are placed to the rigtht of the previous. 不知道为什么将新的子视图放置到以前的视图中。 To put your subviews to the right place, You have to set their frames manually. 为了将子视图放置在正确的位置,您必须手动设置其框架。 For example: 例如:

UIView *greenCircle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[myAccessoryView addSubview:greenCircle];

Hope that helps. 希望能有所帮助。

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

相关问题 附件披露指示器未显示在自定义单元格中 - Accessory Disclosure indicator is not showing up in custom cell Objective C细胞附件视图 - Objective C Cell Accessory view UITableViewCell中的UIImage作为附件视图未显示 - UIImage as accessory view in UITableViewCell not showing 当通过表格单元格附件在UINavigation设置中显示视图控制器时,如何知道它来自哪个表格单元格? - When showing a view controller in a UINavigation setup from a table cell accessory, how do I know which table cell it came from? 地图注释未正确显示附件视图 - Map annotation not showing accessory view properly iOS根据NSMutableArray值在Uitableview中更改附件视图单元格图像 - IOS Change Accessory View Cell Image in Uitableview based on NSMutableArray value 如何画一条线划分单元格的辅助视图 - How To Draw A Line Dividing The Cell's Accessory View 表单元格在表视图的错误部分中显示 - table cell showing up in wrong section in table view UICollectionView Vertical显示最后一半的单元格 - UICollectionView Vertical showing half the cell in the end 调用didSelectRowAtIndexPath时激活单元格的辅助视图(UISwitch) - Activate cell's accessory view (UISwitch) when didSelectRowAtIndexPath is called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM