• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: running code when all notifications have been processed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: running code when all notifications have been processed?


  • Subject: Re: running code when all notifications have been processed?
  • From: "Julien Jalon" <email@hidden>
  • Date: Sat, 18 Feb 2006 00:21:56 +0100

-(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:
>
> 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:

This email sent to email@hidden

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

  • Prev by Date: Re: *Still* Crashing Cross Development
  • Next by Date: Re: *Still* Crashing Cross Development
  • Previous by thread: running code when all notifications have been processed?
  • Next by thread: Using NSDateFormatter, and sorting issues
  • Index(es):
    • Date
    • Thread