我有一個VC子視圖。在subview level
我有一個按鈕。我希望按鈕導致視圖被更新。按鈕來觸發drawRect重繪視圖
IBAction
代碼位於VC中。目前所做的是切換BOOL
值。
返回子視圖drawRect:方法是測試BOOL
並相應地更改視圖的代碼。
我的觀察是,當按下按鈕時,IBAction代碼會運行,切換BOOL
,但drawRect:
方法不會被調用。
我試着手動調用drawRect(不好的做法,並沒有工作)。我試着調用setNeedsDisplay,但這也不起作用(無法弄清楚如何引用以編程方式創建的子視圖)。
建議歡迎。
IBAction爲代碼是微不足道的,但低於包括:
- (IBAction)rotateWindowButtonWasPressed:(id)sender
{
// just flip the boolean here. Need to make the code change in drawRect: in top2View.m
if ([myGlobals gWinVertical])
[myGlobals setGWinVertical:NO];
else
[myGlobals setGWinVertical:YES];
// Hoping this would force a redraw, but bounds have to change...:(
//_top2ViewOutlet.contentMode = UIViewContentModeRedraw;
}
漂亮的捷徑:[myGlobals setGWinVertical:![myGlobals gWinVertical]]; – 2013-02-26 14:26:42
謝謝slugster :) – Tony 2013-02-27 03:43:00