Re: Canceling NSInvocationOperation
Re: Canceling NSInvocationOperation
- Subject: Re: Canceling NSInvocationOperation
- From: claw <email@hidden>
- Date: Sun, 13 Feb 2011 11:05:19 +0100
in apple documentation, they are talking about cancel & isCancelled method
the fact is texto : "cancelling an operation does not immediately force it to stop what it is doing"
so why not add another method , it's goal : verify the availability to iterate the queue inside the nsoperation and the result can be a array of information about index effectively done and so on .... or why not produce a dictionary contains all the information why you want absolutely the operation to cancel... so i hope not be out of your initial question, but my goal was to preserve MVC code design ( a controller object versus model object ).
Le 12 févr. 2011 à 21:43, Chase Latta a écrit :
> Hello all,
>
> I have run into a situation that I don't quite have a solution for. I
> have a UIScrollView that holds a bunch of CALayers. My controller is
> set up to check and see if it can cache layers that are offscreen
> after the user scrolls a certain amount. I found that doing this on
> the main thread was causing my scrolling to not be very smooth so I
> decided to use NSInvocationOperations to figure out what can be cached
> in an operation queue.
>
> Everything is working fine but I am not sure how I deal with canceling
> the operation. If I were subclassing NSOperation I would simply check
> to see if [self isCancelled] returned true and go from there but if I
> throw this into my method that I am passing to the
> NSInvocationOperation I will just be calling this on my controller
> object. I guess the root of my question is how do I access the
> operation from within my method that I am passing to
> initWithTarget:selector:object when I create my invocation operation?
> I guess I could just create a subclass of NSOperation but I would like
> to avoid this because I think it would be overkill.
> ---------------------------
> // Some Code:
> - (void)myOperationInController;
> {
> // Do stuff
> if (![self isCancelled]) // <---- I need to access the operation
> here, self refers to my controller
> [self performSelectorOnMainThread...]
> }
>
> - (void)scrollViewDidScroll:(UIScrollView *)scrollView
> {
> // Note: I am not creating an operation every time the user
> scrolls in my actual application
> NSInvocationOperation *op = [[NSInvocationOperation alloc]
> initWithTarget:self selector:@selector(myOperationInController)
> object:nil];
> [self.oprationQueue addOperation:op];
> [op release];
> }
>
> ---------------------------
>
>
> Thanks in advance,
> Chase
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden