Skip to content

Commit

Permalink
从StackView中删除添加的subView
Browse files Browse the repository at this point in the history
我在TableViewCell中使用StackView 重用时会出现重复添加view的问题,发现在addArrangedSubView 或
insertArrangedSubview:atIndex: 中 调用了 [self addSubview:view] 或 [self
insertSubview:view atIndex:stackIndex] 但并没有在removeArrangedSubview:
中删除添加的view
  • Loading branch information
sdaheng committed Dec 17, 2015
1 parent e271851 commit aefb40b
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions FDStackView/FDStackView.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ - (void)removeArrangedSubview:(UIView *)view {
}
[self removeHiddenObserverForView:view];
[self.mutableArrangedSubviews removeObject:view];
[view removeFromSuperview];
[self.alignmentArrangement removeItem:view];
[self.distributionArrangement removeItem:view];
[self updateLayoutArrangements];
Expand Down

1 comment on commit aefb40b

@github-xiaogang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边有问题,请参考UIStackView系统removeArrangedSubview实现:

系统原生的UIStackView的removeArrangedSubview方法的注释是这样的:
Removes the provided view from the stack’s array of arranged subviews.
This method removes the provided view from the stack’s arrangedSubviews array. The view’s position and size will no longer be managed by the stack view. However, this method does not remove the provided view from the stack’s subviews array; therefore, the view is still displayed as part of the view hierarchy.
To prevent the view from appearing on screen after calling the stack’s removeArrangedSubview: method, explicitly remove the view from the subviews array by calling the view’s removeFromSuperview method, or set the view’s hidden property to YES.

有人提出issue: #35

Please sign in to comment.