我有一个UITableView项目列表。选择一个项目将推送一个viewController,然后继续执行以下操作。 from method viewDidLoad我为我的子视图的on所需的数据启动了一个URLRequest - 一个drawRect覆盖的UIView子类。当数据从云端到达时,我开始构建我的视图层次结构。有问题的子类传递数据,它的drawRect方法现在拥有了它需要呈现的所有东西。什么是强制UIView重绘的最强大的方法?
但是。
因为我没有明确地调用drawRect - Cocoa-Touch处理 - 我没有办法通知Cocoa-Touch我真的很想要这个UIView子类来呈现。什么时候?现在会很好!
我试过[myView setNeedsDisplay]。有时这种方法有效。很斑点。
我一直在这个摔跤几个小时。能否请某个人为我提供一个坚实可靠的方法来强制UIView重新渲染。
下面是代码到视图馈送数据的片段:
// Create the subview
self.chromosomeBlockView = [[[ChromosomeBlockView alloc] initWithFrame:frame] autorelease];
// Set some properties
self.chromosomeBlockView.sequenceString = self.sequenceString;
self.chromosomeBlockView.nucleotideBases = self.nucleotideLettersDictionary;
// Insert the view in the view hierarchy
[self.containerView addSubview:self.chromosomeBlockView];
[self.containerView bringSubviewToFront:self.chromosomeBlockView];
// A vain attempt to convince Cocoa-Touch that this view is worthy of being displayed ;-)
[self.chromosomeBlockView setNeedsDisplay];
干杯, 道格
罗布, 这里是我的清单。 1)我有数据吗?是。我在一个方法中创建视图 - hideSpinner - 从connectionDidFinishLoading在主线程上调用:因此: [self performSelectorOnMainThread:@selector(hideSpinner)withObject:nil waitUntilDone:NO]; 2)我不需要立即绘制。我只需要它。今天。目前,它完全是随机的,并且不受我的控制。 [myView setNeedsDisplay]是完全不可靠的。 我甚至竟然在viewDidAppear:中调用[myView setNeedsDisplay]。 Nuthin'。可可根本无视我。 Maddening !! – dugla 2009-10-01 13:33:01
看着你的代码,你想确认的第一件事是,contatinerView本身就在屏幕上。把其他东西(例如UILabel),看看是否吸引。其次,确保self.containerView不是零。 “没有任何反应”的主要原因是向nil发送消息。你不应该在这里需要setNeedsDisplay,但是如果你这样做了,将它发送到containerView而不是chromosomeBlockView会更典型。你问容器视图重绘自己和它的子视图(你已经重新排列),其中一个碰巧是chromosomeBlockView。 – 2009-10-01 17:37:28
我发现,通过这种方法,'setNeedsDisplay'和'drawRect:'的实际调用之间通常会有一段延迟。虽然通话可靠性在这里,但我不会称之为“最强大的”解决方案 - 理论上,强大的绘图解决方案应该在返回要求抽取的客户端代码之前立即完成所有绘图。 – 2013-05-08 02:36:52