开发者

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.


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜