我有一个带有项目列表的UITableView.选择一个项目会推送一个viewController,然后继续执行以下操作.从方法viewDidLoad我为我的子视图所需的数据启动了一个URLRequest - 一个覆盖了drawRect的UIView子类.当数据从云端到达时,我开始构建我的视图层次结构.有问题的子类传递数据,它的drawRect方法现在具有渲染所需的一切.
但.
因为我没有显式调用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];
Run Code Online (Sandbox Code Playgroud)
干杯,道格