UIView with top space 对 UIStackView 的约束未显示在 Stackview 下方

UIView with top space Constraint to UIStackView not displayed below Stackview

我的问题有点难以描述:

我正在开发一个笔记应用程序。我的 "Create a new note" - 屏幕包含一个垂直堆栈视图,用于显示与新笔记关联的待办事项。 在这个 stackview 下面有一个 UIView,用户可以在其中添加提醒:

堆栈视图包含特定数量的子视图。在构建用户界面时我不知道这个数量,而是所有子视图都将在运行时以编程方式添加。 我希望提醒视图始终停留在我的堆栈视图下方。所以我添加了一个 Top Space 约束。

但在以编程方式向堆栈视图添加项目(并因此扩大)时,此约束似乎没有影响。

编辑: 这是我添加子视图的代码:

[_todoContainer.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)];
    int y = 0;
    for (NoteTodoEntity* entity in _note.todos) {
        NotinaryTodoView* view = [[[NSBundle mainBundle] loadNibNamed:@"NotinaryTodoView" owner:self options:nil] objectAtIndex:0];
        view.frame = CGRectMake(_todoContainer.frame.origin.x, y, _todoContainer.frame.size.width, 40);
        [view layoutIfNeeded];
        y+=40;
        view.currentEntity = entity;
        [view.todoDeleteButton addTarget:self action:@selector(todoActionPressed:) forControlEvents:UIControlEventTouchUpInside];
        [_todoContainer addSubview:view];
    }
    [self.view layoutIfNeeded];

解决方案相当简单。 为我以编程方式添加的视图设置框架是错误的,我不得不使用约束和 StackView "addArrangedSubView" 方法:

for (NoteTodoEntity* entity in _note.todos) {
        NotinaryTodoView* view = [[[NSBundle mainBundle] loadNibNamed:@"NotinaryTodoView" owner:self options:nil] objectAtIndex:0];
         [view.heightAnchor constraintEqualToConstant:40].active = true;
        [view.widthAnchor constraintEqualToConstant:self.view.frame.size.width].active = true;
        view.currentEntity = entity;
        [view.todoDeleteButton addTarget:self action:@selector(todoActionPressed:) forControlEvents:UIControlEventTouchUpInside];
        [_todoContainer addArrangedSubview:view];
    }