2012-07-07 52 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”方法吗?)。