Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 位置操作问题_Objective C_Ipad_Nsthread - Fatal编程技术网

Objective c 位置操作问题

Objective c 位置操作问题,objective-c,ipad,nsthread,Objective C,Ipad,Nsthread,我想知道如何删除重复的nsoperations,即是否有方法检查nsoperation队列并查看我是否提出了重复的请求 基本上,我请求的图像取决于iphone屏幕的旋转。加载视图时,将调用两次shouldautorate If(rotation==portrait){ request portrait image. } 问题是应该检查自动旋转两次。在两张照片上,它都是肖像,因此要求两次相同的图像。有人有好主意吗?我忘了说我在排队 谢谢。新的、更好的答案: 不要使用shouldAutorot

我想知道如何删除重复的nsoperations,即是否有方法检查nsoperation队列并查看我是否提出了重复的请求

基本上,我请求的图像取决于iphone屏幕的旋转。加载视图时,将调用两次shouldautorate

If(rotation==portrait){
  request portrait image.
}
问题是应该检查自动旋转两次。在两张照片上,它都是肖像,因此要求两次相同的图像。有人有好主意吗?我忘了说我在排队


谢谢。

新的、更好的答案:

不要使用
shouldAutorotate…
方法。它只询问是否允许发生旋转。这可能随时发生,不一定会导致旋转。相反,请使用
willRotate…
didRotate…
,因为这些方法仅被精确调用一次,并且仅在实际发生旋转时调用

您的操作将只添加一次


古老但不是错误的答案:

使用实例变量来记住上次看到的旋转如何?像这样:

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

是的,我考虑过了,但这不是骇客吗?哦,嗯,nvm,会坚持的。这比检查我的队列并查看是否有重复项要简单得多。预防更好。我被告知我们不应该使用shouldautorotate方法,而应该使用willrotate或didrotate方法。当然,应该使用后者。原因很简单:第一个会要求旋转,但实际上并不要求旋转发生。后两者实际上执行旋转。(笨拙的我)在这些情况下,你也不需要检查:旋转动作只发生一次。我会相应地调整我的职位。