简体   繁体   English

setNeedsDisplay可在iPhone上使用,但不能在iPad上使用

[英]setNeedsDisplay works on iPhone but not on iPad

The view in question was created in IB on the root view and wired to a class method in the rootViewController. 有问题的视图是在IB的根视图上创建的,并连接到rootViewController中的类方法。 In the view's class method I am overriding drawRect to draw it's content. 在视图的类方法中,我重写了drawRect以绘制其内容。 I am calling setNeedsDisplay on the view from the rootViewController after the user changes some parameters. 用户更改某些参数后,我将从rootViewController的视图上调用setNeedsDisplay。

On the iPhone this works fine. 在iPhone上,此功能正常。 On the iPad, however, drawRect in the class method does not get called. 但是,在iPad上,不会调用class方法中的drawRect。

I suspect that the reason for this has to do with the drawing cycle. 我怀疑其原因与绘制周期有关。 On the iPhone the view used by the user to change the parameters is pushed onto the screen over the view in question. 在iPhone上,用户用于更改参数的视图被推到相关视图上方的屏幕上。 On the iPad this view is added to the root view above, not over, the view in question. 在iPad上,此视图被添加到相关视图的上方而不是上方的根视图中。 So when the view used to change the parameters is closed, unlike on the iPhone, a drawing cycle is not generated and so the invalidated view is not updated. 因此,当关闭用于更改参数的视图时,与在iPhone上不同,该视图不会生成绘制周期,因此无效的视图不会更新。

I'm stuck. 我被卡住了。 Any help would be appreciaetd. 任何帮助将不胜感激。

Found the problem... 发现了问题...

I discovered that in the xib being used by the root view controller for the iPad, the wiring for the UIView object in question was some how corrupted. 我发现,在iPad的根视图控制器使用的xib中,所讨论的UIView对象的连线有些损坏。 When I hovered over the bullet of it's iIBOutlet variable in the .h file an UISegmentedControl elsewhere in the xib would be selected instead of the intended UIView. 当我将鼠标悬停在.h文件中的iIBOutlet变量的项目符号上时,将选择xib中其他位置的UISegmentedControl而不是预期的UIView。 Right-Clicking the UISegmentedControl did not show that the link existed. 右键单击UISegmentedControl并不表明该链接存在。 The only way I was able to get it fixed was to remove all the wiring from both objects and rewire them properly. 我能够修复的唯一方法是从这两个对象上除去所有布线并正确地重新布线。 Calling setNeedsDisplay now works. 现在可以调用setNeedsDisplay。 as expected, on the iPad just like it does on the iPhone. 正如预期的那样,在iPad上就像在iPhone上一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM