在基于选项卡栏的应用程序中,控制器发布另一个控制器的数据! !
我制作了一个 ViewBased 应用程序,在应用程序委托中我设置了一个 UITabBarCotntroller,在应用程序中我有不同的视图控制器,其中两个在 UITextView 和标签中显示文本,另一个是我的“ShakeController”UIViewController,其中我设置了一个 UIAcelerometerDelegate,在其中创建了一个 UIAccelerometer 实例,在管理抖动的方法中一切正常,在这个控制器中我还设置了一个 UIImageView 来制作简单的动画,在视图中设置了 Did Load 方法我的 imageView.animation 到 UIImage 数组。
我的问题是:当应用程序启动时,我使用 ViewController,一切工作正常,但是当我点击选项卡栏中的 ShakeController 项目,然后当我回到其他控制器时,标签看起来像:label 和 textView 像:Lorem ipsum..... IB中UItextView的文本。
我注意到,如果我将 imageView 的初始化注释到图像数组,我可以导航项目(从视图控制器到另一个视图控制器),而无需更改标签并保持我想要的状态。
请注意,这两个控制器位于 UINavigationController 中。
(我使用@proprety(nonnatomic,retain)然后@synthesize ...然后releqse在标签textview和我的uiimageView的dealloc中)
不知道该怎么办,谢谢大家
I've made a ViewBased app, in the app delegate i've set a UITabBarCotntroller, in the app i have different view Controller two of them displays text in a UITextView and labels, the other one is my "ShakeController" a UIViewController in which i've set a UIAcelerometerDelegate, in it i create a instance of UIAccelerometer, in the method which manages the shake everything works fine, in this controller i have also set a UIImageView to make a simple animation, in the view Did Load method i set my imageView.animation to an array of UIImage.
My problem is : when the app is launched i use the ViewControllers and everything work fine, but when i tap the ShakeController item in the tab bar and then when i come back to the other controllers the label looks like : label and textView like : Lorem ipsum..... the text of UItextView in IB.
I have noticed thaht if i comment the initialisation of my imageView to the array of image i can navigate the items (from a view controller to another) without the label change and stay what i want them to be.
Notice that the two controllers are in a UINavigationController.
(i use @proprety (nonnatomic, retain) then @synthesize ... then releqse in the dealloc for the labels textview and my uiimageView)
Do not know what to do thanks to all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难理解你在这里问什么......我重新读了三遍,但我仍然不确定!
由于当您注释掉 imageView 动画初始化时,您发现问题(另一个视图中的数据被“释放”)消失了,因此我得出结论,您正在使用大量 iPhone 内存,这意味着它会自动卸载任何不可见的视图控制器。它会很快地完成此操作以保留内存。
你没有说你的动画中有多少图像,但仅仅 10 个中大图像就足以触发内存问题;如果你想使用 20/30+,你必须寻找另一种方法。
您可以尝试先将几帧加载到图像中,然后在循环计时器上交换它们。但如果它不仅仅是非常基本的动画,您将需要陷入核心动画:http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/WhatisCoreAnimation.html# //apple_ref/doc/uid/TP40004689
Quite hard to understand what you're asking here... I re-read it three times and I'm still not sure!
Since you find the problem (the data in the other view being "released") goes away when you comment out your imageView animation initialisation, I would conclude that you are using up a large amount of the iPhone's memory which means that it is automatically unloading any un-seen view controllers. It will do this quite quickly to preserve memory.
You don't say how many images are in your animation, but just 10 medium-large images can be enough to trigger memory issues; if you are wanting to use 20/30+ you have to look for another way.
You can try just loading a few frames into your image first and then swapping them out on a recurring timer. But if it's anything more than very basic animation you'll need to get stuck in to core animation instead: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/WhatisCoreAnimation.html#//apple_ref/doc/uid/TP40004689