编辑不同类的出口 - 可可

时间:2014-04-22 11:24:09

标签: cocoa nsview nsobject nsprogressindicator

我需要 通过与定义插座的类不同的类来更新NSProgressIndicator的值

Es:

  • 在A.h课程中,我定义NSProgressIndicator的出口并链接它。
  • 在A.m类中,我有一个方法来更新指标的doubleValue。
  • 在B级。我通过A类的方式调用方法,但没有任何反应

如果我在A类中使用相同的方法 ,那么可以正常工作

我错过了什么?

//REQUESTED CODE:
//Class A (AppDelegate)
A.m
//Other stuff
-(void)update_indicator:(double)value {
//Method that updates the value of the indicator
[progress_indicator setDoubleValue:(double)value];
[progress_indicator setNeedsDisplay:YES];
}

//Class B (Drawing class - subclass of NSView)
B.m
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
//Create istance;
A *istance = [[A alloc] init]; //Alloc class A and init it
[A update_indicator:50.0];
//Other code..
}

奇怪的是,如果我在A类中调用-(void)update_indicator:(double)value,其中定义了插座,它可以正常工作,如果我从B调用它正在被调用但是进度条没有显示。

1 个答案:

答案 0 :(得分:0)

如果A是应用程序的委托类,您可以使用此[[NSApplication sharedApplication]delegate]获取好的实例,而不是创建新实例。

否则,你应该把A类变成单身。

锁定此示例http://www.galloway.me.uk/tutorials/singleton-classes/