0
现在,我有几行ObjC来轮询设置的默认打印机,并且在我的应用程序中它应该使用该新打印机的名称更新标签,但到目前为止它不是加工。在运行时更新默认打印机名称
在我的控制,我有以下几点:
[self updatePrinter];
其中要求这个小方法:
- (void)updatePrinter {
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
self.printerName.stringValue = printInfo.printer.name;
NSLog(@"Printer: %@", printInfo.printer.name);
}
当它击中我的方法(在viewDidLoad
),它将填充标签printerName
正确。
我尝试添加一个计时器轮询新打印机的默认设定:
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(updatePrinter)
userInfo:nil
repeats:YES];
这正常运行,但如果我打开系统偏好设置,更改默认打印机,它继续打印的名称旧的默认值。如果我重新启动应用程序,它只会有不同的表现。
如何在运行期间将新的默认值反映到我的应用程序中?
感谢。通过比较,我想出了一个非常复杂的解决方案,涉及PM *函数,并认为initWithDictionary:需要所有设置。这对我来说非常简单而有效。 – drewpotential