2012-07-07 54 views
1

在我的視圖控制器我有一個方法-(void) showDescription: (id) description女巫確實兩件事情奇怪的行爲的Xcode

  1. 顯示在標籤
  2. 說明和運行在該視圖的方法,給出了一個setNeedsDisplay到 查看。

現在這裏是奇怪的事情:

如果我在我的代碼的另一種方法調用showDescription,它進入showdescription(我有一個NSLog的),讀取描述OK(另一個的NSLog),但不會更改標籤或運行setNeedsDisplay(無NSLog)的查看方法。

但是...如果我從一個按鈕調用相同的方法它工作得很好:放置label.text並重新繪製我的視圖。

當我在showDescription中放置兩個斷點之一併在視圖方法中放置一個斷點時,我意識到了相同的行爲。在第一種情況下,它不會轉到視圖方法,而是在第二種情況下(UIAction)。

這有多奇怪?有人知道爲什麼嗎?因爲我迷路了....

非常感謝

Clemcore

類:

  • GraphViewController:UIViewController中
  • graphView:UIView的

**GraphViewController.m* ** * ***

-(void) showDescription: (id) description 
    {  
     NSString* text= [(NSString*) description copy]; 
     self.lableDescription.text=text; //display description in label 
    [self.graphView redrawView]; 
    } 


    -(void)displayGraph 
    { 
     NSLog(@"GraphViewController.displayGraph"); 
     NSLog(@"self.programData %@",self.programData); //these work fine 
     NSLog(@"description lable %@",self.programDescriptionData); 


     [self showDescription:self.programDescriptionData]; 
     [self.graphView redrawView]; 

    } 

    - (IBAction)redraw { 
    NSLog(@"IBAction redraw"); 
    NSLog(@"myData %@",self.graphView.myData); 
    [self showDescription:@"CCCC"]; 
    [self.graphView redrawView]; 

} 

graphView.m* **

-(void)redrawView //public method 
{ 
    NSLog(@"redrawView"); 
    [self setNeedsDisplay]; 
} 

我對獅子10.7.4

這裏使用的Xcode 4.3.3是發生了什麼:

如果我叫displayGraph的programData和programDescriptionData是罰款(的NSLog顯示正確的話),但...它不」 t改變標籤,它不會去redrawView(沒有NSLog redrawView)。

Here is the log: 
2012-07-08 12:29:19.193 CalculatorGraph[2641:f803] GraphViewController.displayGraph 
2012-07-08 12:29:19.194 CalculatorGraph[2641:f803] self.programData (
    22 
) 
2012-07-08 12:29:19.194 CalculatorGraph[2641:f803] description lable 22 
2012-07-08 12:29:19.195 CalculatorGraph[2641:f803] text is 22 

現在,如果我按下按鈕它似乎工作:更新標籤並重新繪製視圖中的視圖和drawRect。看到我的問題?

2012-07-08 14:16:54.358 CalculatorGraph[2743:f803] IBAction redraw 
2012-07-08 14:16:54.358 CalculatorGraph[2743:f803] myData <GraphViewController: 0x6d3f1f0> 
2012-07-08 14:16:54.359 CalculatorGraph[2743:f803] text is CCCC 
2012-07-08 14:16:54.359 CalculatorGraph[2743:f803] redrawView 
2012-07-08 14:16:54.360 CalculatorGraph[2743:f803] redrawView 
2012-07-08 14:16:54.362 CalculatorGraph[2743:f803] graphView.drawRect 
2012-07-08 14:16:54.363 CalculatorGraph[2743:f803] data in graphView DrawRect is: <GraphViewController: 0x6d3f1f0> 

截圖我的故事板:請看到我的評論鏈接下...

謝謝

+0

如果問題不清楚或需要看一些代碼讓我知道,我會很樂意。 – Clemcore 2012-07-07 11:11:35

+0

請更好地標記問題;即平臺,語言和您正在使用的課程。 – trojanfoe 2012-07-07 12:17:42

+0

你確定當你從你的代碼中調用它時,你實際上調用了正確對象上的方法(即可見視圖控制器和IBOutlet連接到標籤等)? 99.99999%是導致問題的編碼,而不是IDE或編譯器。 – ChrisH 2012-07-07 17:02:34

回答

0

你確定你是IBOutlet中lableDescription?可能是labelDescription? 加:你應該永遠不會「[self.graphView redrawView];」;你應該改爲「[self.graphView setNeedsDisplay:YES]」。 「showDescription」是否是適當的方法名稱? (你有一個「hideDescription」方法嗎?)。