user281300
user281300

Reputation: 1457

NSInvocationOperation Question

I would like to know how to remove duplicate nsoperations, i.e is there a way to check the nsoperation queue and see if I am making a duplicate request?

Basically, I am requesting images depending on the iphone screen rotation. When the view is loaded the shouldautorate is called twice.

If(rotation==portrait){
  request portrait image.
}

The issue is that shoud autorotate will be checked twice. And on both ocassions, it will turn out to be portrait hence requesting the same image twice. Anyone with a good idea? I forgot to mention I am using a queue.

Thanks.

Upvotes: 0

Views: 178

Answers (1)

Max Seelemann
Max Seelemann

Reputation: 9364

NEW, better answer:

Don't use the shouldAutorotate... method. It only asks whether a rotation is allowed to happen. This may happen any time and may not necessarily lead to a rotation. Instead, use willRotate... or didRotate..., as these methods are only invoked exactly once and only if the rotation actually happens.

Your operation will then be added only once.


OLD, but not false answer:

How about using a instance variable to remember the last seen rotation? Like so:

if (rotation != lastSeenRotation) {
    // REQUEST image here
}

Upvotes: 1

Related Questions