Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: running code when all notifications have been processed?



-(void)modelChanged:(NSNotification *)notification{
    // naive version

    // first cancel any previous call to arrange arrangeMySubviews
    [NSObject cancelPreviousPerformRequestsWithTarget:superview
selector:@selector(arrangeMySubviews) object:nil];
    // schedule the call to arrangeMySubviews
    [superview peformSelector:@selector(arrangeMySubviews)
withObject:nil afterDelay:0];
}

but this should be cleaner and safer to make your superview's
correctly handles this stuff by using the same ideas used for
"setNeedsDisplay:" methods:

@implementation MySuperViewClass

[...]

- (void)setNeedsToArrangeMySubviews:(BOOL)flag
{
    [NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(arrangeMySubviews) object:nil];
    if(flag) {
        [self peformSelector:@selector(arrangeMySubviews)
withObject:nil afterDelay:0];
    }
}

- (void)arrangeMySubviews
{
    [self setNeedsToArrangeMySubviews:NO];
    ... real work here...
}

[...]

@end

On 2/17/06, Joshua Scott Emmons <email@hidden> wrote:
> I have a view that contains a variable number of smaller subviews.
> These subviews all change their size and appearance in response to a
> notification that is posted by my model. After the subviews have all
> updated themselves, their superview needs to arrange them. Right now
> I have something like the following in the subview:
>
> -(void)modelChanged:(NSNotification *)notification{
>         //do stuff
>
>         [superview arrangeMySubviews];
> }
>
>
> This works, but has the obvious disadvantage that it calls the
> superview's arrangeMySubviews once for EACH subview that processes
> this notification. What should really happen is that
> arrangeMySubviews should be called only once after all the subviews
> have received and processed their notifications. Is there a way to be
> notified when all the objects sent a notification have processed it?
> Or is there a mechanism that will let me queue up many duplicate
> selectors, only sending the final message once?
>
>
> Many thanks,
> -Joshua Emmons
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/email@hidden
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >running code when all notifications have been processed? (From: Joshua Scott Emmons <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.