[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: remove -removeSubview:
From: |
Banlu Kemiyatorn |
Subject: |
Re: remove -removeSubview: |
Date: |
Fri, 29 Apr 2011 02:09:12 +0700 |
----- Original message -----
> > * Forgot not to modify the array during the enumeration.
> > * Remove the extra subviews to improve the lookup speed on additions.
> >
> > why it's _sub_views and not _subviews?
>
> I don't know, but I have observed that various GNUstep classes written a
> long ago have ivars named in a similar way.
>
> > - (void) setSubviews: (NSArray *)newSubviews
> > {
> > NSEnumerator *en;
> > NSView *aView;
> >
> > en = [[NSArray arrayWithArray:_subviews] objectEnumerator];
> > while ((aView = [en nextObject]))
> > {
> > if (NO == [newSubviews containsObject:aView])
> > {
> > [aView removeFromSuperview];
> > }
> > }
> >
> > NSMutableArray *uniqNew = [NSMutableArray array];
> > en = [newSubviews objectEnumerator];
> > while ((aView = [en nextObject]))
> > {
> > id supersub = [aView superview];
> > if (supersub != nil && supersub != self)
> > {
> > [NSException raise:NSInvalidArgumentException
> > format:@"Superviews of new subviews must be either nil or
> > receiver."]; }
> >
> > if ([uniqNew containsObject:aView])
> > {
> > [NSException raise:NSInvalidArgumentException
> > format:@"Duplicated new subviews."];
> > }
> >
> > if (NO == [_subviews containsObject:aView])
> > {
> > [self addSubview:aView];
> > }
> >
> > [uniqNew addObject:aView];
> > }
> >
> > ASSIGN(_subviews, uniqNew);
> > }
>
> This looks ok. However I think this code doesn't match this requirement
> written in the Cocoa doc: "And any views that are in both subviews and
> newSubviews are moved in the subviews array as needed, without being
> removed and re-added."
>
> Cheers,
> Quentin.
Im still not sure why it is not. I thought of that case, only views that werent shared by both arrays will either be added or removed, else they only got sorted and assigned back as uniqNew.
- Re: remove -removeSubview:, (continued)
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/27
- Re: remove -removeSubview:, Wolfgang Lux, 2011/04/27
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/27
- Re: remove -removeSubview:, Quentin Mathé, 2011/04/27
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/27
- Re: remove -removeSubview:, Quentin Mathé, 2011/04/28
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/28
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/27
- Re: remove -removeSubview:, Banlu Kemiyatorn, 2011/04/28
- Re: remove -removeSubview:, Quentin Mathé, 2011/04/28
- Re: remove -removeSubview:,
Banlu Kemiyatorn <=