【发布时间】:2019-10-24 22:55:03
【问题描述】:
我收到了来自实时用户的崩溃报告 我有 NSObject 有 nsstring
@interface MountedVolume : NSObject
@property (nonatomic, strong) NSString *name;
@end
视图控制器有文本字段,当通知时它的值会改变 收到了。
@interface ViewController : NSViewController {
MountedVolume *selectedVolume;
__weak IBOutlet NSTextField *txtVolumeName;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserverForName:DCNotificationNameVolumesUpdated object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
dispatch_async(dispatch_get_main_queue(), ^{
//crash report says in this line it got crashed
txtVolumeName.stringValue = selectedVolume.name;
});
}];
}
@end
下面是崩溃报告,有什么建议可以解决这个问题吗?
崩溃报告
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x7fff6ac2639d objc_msgSend + 29
1 AppKit 0x7fff3db3d868 -[NSCell _objectValue:forString:errorDescription:] + 157
2 AppKit 0x7fff3db3d71d -[NSCell setStringValue:] + 40
3 AppKit 0x7fff3db95044 -[NSControl setStringValue:] + 135
4 MyApp 0x104de865b __40-[ViewController viewDidLoad]_block_invoke_3 (ViewController.m:172)
5 libdispatch.dylib 0x7fff6c3ab5f8 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x7fff6c3ac63d _dispatch_client_callout + 8
7 libdispatch.dylib 0x7fff6c3b768d _dispatch_main_queue_callback_4CF + 1135
8 CoreFoundation 0x7fff40435f56 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
9 CoreFoundation 0x7fff40435683 __CFRunLoopRun + 2300
10 CoreFoundation 0x7fff40434b35 CFRunLoopRunSpecific + 459
11 HIToolbox 0x7fff3f71396b RunCurrentEventLoopInMode + 292
12 HIToolbox 0x7fff3f7136a5 ReceiveNextEventCommon + 603
13 HIToolbox 0x7fff3f713436 _BlockUntilNextEventMatchingListInModeWithFilter + 64
14 AppKit 0x7fff3daad987 _DPSNextEvent + 965
15 AppKit 0x7fff3daac71f -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1361
16 AppKit 0x7fff3daa683c -[NSApplication run] + 699
17 AppKit 0x7fff3da95d7c NSApplicationMain + 777
18 libdyld.dylib 0x7fff6c3f93d5 start + 1
【问题讨论】:
-
你确定
selectedVolume.name的值在主循环中执行之前没有改变吗?
标签: objective-c macos crash appkit