Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when adding a new arranged subview #83

Open
zeusent opened this issue Feb 26, 2016 · 2 comments
Open

Crash when adding a new arranged subview #83

zeusent opened this issue Feb 26, 2016 · 2 comments

Comments

@zeusent
Copy link

zeusent commented Feb 26, 2016

So, first of all let me say thank you! This little fallback solution for UIStackView is awesome.

I've been trying to use it but I do have a problem. I create my OAStackView in Interface Builder where I pre-populate it with some subviews. But then, in code I want to add some more views and I thought that the method insertArrangedSubview:atIndex is what I need.

The problem is that when I do that it crashes. Here's a screen shot of the line that causes the crash:

screen shot 2016-02-26 at 11 23 39

As you can see it seems that self.mutableArrangedSubviews is empty and I've looked all over your code to see where it get's populated, if it ever does, and I can't really find the place that does that.

So, do you think this is a bug or is there a way you can help me?

Thanks

@zeusent
Copy link
Author

zeusent commented Feb 26, 2016

Ok, I found a quick fix. It seems that adding these lines:

for (UIView *view in self.subviews) {
    [self.mutableArrangedSubviews addObject:view];
}

in initWithCoder: will fix my issue. So here's my complete implementation of that method:

- (instancetype)initWithCoder:(NSCoder *)decoder {
    self = [super initWithCoder:decoder];

    if (self) {
        [self commonInitWithInitalSubviews:@[]];

        if ([NSStringFromClass([self class]) isEqualToString:@"UIStackView"]) {
            self.axis = [decoder decodeIntegerForKey:@"UIStackViewAxis"];
            self.distribution = [decoder decodeIntegerForKey:@"UIStackViewDistribution"];
            self.alignment = [decoder decodeIntegerForKey:@"UIStackViewAlignment"];
            self.spacing = [decoder decodeDoubleForKey:@"UIStackViewSpacing"];
            self.baselineRelativeArrangement = [decoder decodeBoolForKey:@"UIStackViewBaselineRelative"];
            self.layoutMarginsRelativeArrangement = [decoder decodeBoolForKey:@"UIStackViewLayoutMarginsRelative"];
        }

        for (UIView *view in self.subviews) {
            [self.mutableArrangedSubviews addObject:view];
        }

        [self layoutArrangedViews];
    }

    return self;
}

@delebedev
Copy link
Collaborator

It looks like regression caused by my fix of KVO: fb7d741

:( no idea how to solve your issue correctly at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants