我有一個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