gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: remove -removeSubview:


From: Banlu Kemiyatorn
Subject: Re: remove -removeSubview:
Date: Thu, 28 Apr 2011 11:56:22 +0700

* 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?

- (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);
}




-- 
    .----.     Banlu Kemiyatorn
  /.../\...\   漫画家
 |.../  \...|  http://qstx.blogspot.com (Free Software Advocacy & Development)
 |../    \..|  http://feedbat.blogspot.com (Studio Work For Hire)
  \/      \/   http://groundzerostudiocomplex.blogspot.com (Studio Research)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]