I get the following error and stacktrace however the view is not nil (as shown by the logging down right before it)
Stacktrace
2014-02-05 08:29:47.338 MenuTimer[74522:303] An uncaught exception was raised
2014-02-05 08:29:47.338 MenuTimer[74522:303] The contentViewController ((null)) or contentViewController.view is nil.
2014-02-05 08:29:47.340 MenuTimer[74522:303] (
0 CoreFoundation 0x00007fff8e39341c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff87b1ee75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8e3932cc +[NSException raise:format:] + 204
3 AppKit 0x00007fff8157e3da -[NSPopover showRelativeToRect:ofView:preferredEdge:] + 228
4 MenuTimer 0x0000000100002a72 -[MenuTimer onSetTime:] + 818
5 AppKit 0x00007fff814f83d0 -[NSApplication sendAction:to:from:] + 327
6 AppKit 0x00007fff81513348 -[NSMenuItem _corePerformAction] + 394
7 AppKit 0x00007fff81513084 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 117
8 AppKit 0x00007fff815624dd -[NSMenu _internalPerformActionForItemAtIndex:] + 35
9 AppKit 0x00007fff81562359 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 104
10 AppKit 0x00007fff81509176 NSSLMMenuEventHandler + 716
11 HIToolbox 0x00007fff8acff6d4 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 892
12 HIToolbox 0x00007fff8acfec87 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 385
13 HIToolbox 0x00007fff8ad12d90 SendEventToEventTarget + 40
14 HIToolbox 0x00007fff8ad48a30 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 420
15 HIToolbox 0x00007fff8ad7b618 SendMenuCommandWithContextAndModifiers + 59
16 HIToolbox 0x00007fff8ad7b5c4 SendMenuItemSelectedEvent + 178
17 HIToolbox 0x00007fff8ad7b4a5 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 94
18 HIToolbox 0x00007fff8ad5956e _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1726
19 HIToolbox 0x00007fff8ad586c6 _HandlePopUpMenuSelection7 + 596
20 AppKit 0x00007fff81561221 _NSSLMPopUpCarbonMenu3 + 4153
21 AppKit 0x00007fff815601d6 _NSPopUpCarbonMenu3 + 39
22 AppKit 0x00007fff8155fe96 -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 350
23 AppKit 0x00007fff81950959 +[NSStatusBarButtonCell popupStatusBarMenu:inRect:ofView:withEvent:] + 699
24 AppKit 0x00007fff81951ade -[NSStatusItem popUpStatusItemMenu:] + 173
25 MenuTimer 0x0000000100001779 -[StatusBarView mouseDown:] + 633
26 AppKit 0x00007fff814ded08 -[NSWindow sendEvent:] + 11296
27 AppKit 0x00007fff815da11b -[NSStatusBarWindow sendEvent:] + 247
28 AppKit 0x00007fff8147d744 -[NSApplication sendEvent:] + 2021
29 AppKit 0x00007fff812cda29 -[NSApplication run] + 646
30 MenuTimer 0x0000000100002500 -[MenuTimer init] + 2112
31 MenuTimer 0x00000001000031b5 main + 101
32 libdyld.dylib 0x00007fff87fcc5fd start + 1
)
However the following code and output indicates differently. Is it because I don't have an explicit controller?
Code
// create set time window
NSLog(#"Set Time...");
NSLog(#"View %#", self.statusTime.view);
NSLog(#"Frame %#", self.statusTime.view.frame);
NSPopover *popover = [[NSPopover alloc] init];
NSLog(#"Showing popover...");
[popover showRelativeToRect:[self.statusTime.view frame]
ofView:self.statusTime.view
preferredEdge:NSMinYEdge];
Output
2014-02-05 08:29:47.237 MenuTimer[74522:303] Set Time...
2014-02-05 08:29:47.237 MenuTimer[74522:303] View <StatusBarView: 0x6080001b05a0>
2014-02-05 08:29:47.238 MenuTimer[74522:303] Frame <StatusBarView: 0x6080001b05a0>
2014-02-05 08:29:47.238 MenuTimer[74522:303] Showing popover...
You need to set the contentViewController (what the popover is actually showing) before showing it.
i.e.
NSViewController *viewController; // some view controller created programmatically or from a nib
NSPopover *popover = [[NSPopover alloc] init];
popover.contentViewController = viewController; // Missing this.
NSLog(#"Showing popover...");
[popover showRelativeToRect:[self.statusTime.view frame]
ofView:self.statusTime.view
preferredEdge:NSMinYEdge];
The ofView: parameter is just where the popover is being shown from.
Related
While adding child viewcontroller, I am getting following crash,
Here NavigationViewController is extended from UIViewController.
This error is coming when I upgraded to Xcode 9, working successfully on earlier versions of Xcode.
I referred the Link but not getting any satisfied answer, please help me out this,
Thanx in advance. :)
The block of code is:
_mainSectionsController = [[[MainSectionsController alloc] initWithNibName:nil bundle:nil] autorelease];
[self addChildViewController:_mainSectionsController];
**Init method of _mainSectionsController** .
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
self.viewControllers = #
[
[[[NavigationViewController alloc] initWithNibName:nil bundle:nil]
autorelease]
];
return self;
}
**init method of NavigationViewController**
-(id)initWithNibName:(NSString*)nibNameOrNil bundle: (NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (!self) return nil;
self.edgesForExtendedLayout = UIRectEdgeAll;
_navController = [[[UINavigationController alloc] initWithNibName:nil bundle:nil] autorelease];
_navController.get().delegate = self;
_navController.get().navigationBarHidden = YES;
_navController.get().view.clipsToBounds = YES;
_navController.get().view.backgroundColor = [UIColor clearColor];
return self;
}
2018-05-22 10:46:23.112290+0530 [912:19925] -[NavigationViewController _viewControllerSubtreeDidGainViewController:]: unrecognized selector sent to instance 0x7f91ba83c000
2018-05-22 10:46:24.939903+0530 [912:19925] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NavigationViewController _viewControllerSubtreeDidGainViewController:]: unrecognized selector sent to instance 0x7f91ba83c000'
* First throw call stack:
(
0 CoreFoundation 0x000000010f03f12b exceptionPreprocess + 171 .
1 libobjc.A.dylib 0x000000010e640f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010f0c0024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010b2cdf51 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x000000010efc1f78 ___forwarding_ + 1432
5 CoreFoundation 0x000000010efc1958 _CF_forwarding_prep_0 + 120
6 UIKit 0x000000010b246c1d -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 696
7 UIKit 0x000000010b26930e -[UIViewController(UIContainerViewControllerProtectedMethods) addChildViewController:] + 83
8 0x00000001058eeac3 -[MainViewController initWithNibName:bundle:] + 5235
9 0x00000001059876ca -[AppDelegate loadMainViewController] + 122
10 0x0000000105984561 -[AppDelegate application:didFinishLaunchingWithOptions:] + 1137
11 UIKit 0x000000010b091bca -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 299
12 UIKit 0x000000010b093648 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4113
13 UIKit 0x000000010b098aeb -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
14 UIKit 0x000000010b4626f8 111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
15 UIKit 0x000000010b8384c8 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
16 UIKit 0x000000010b4622f1 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
17 UIKit 0x000000010b462b6b -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 696
18 UIKit 0x000000010bde0a69 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
19 UIKit 0x000000010bde0922 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
20 UIKit 0x000000010babd9c8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
21 UIKit 0x000000010bcbcb06 _performActionsWithDelayForTransitionContext + 100
22 UIKit 0x000000010babd88b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
23 UIKit 0x000000010b837b25 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
24 UIKit 0x000000010b09736a -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
25 UIKit 0x000000010b672605 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
26 FrontBoardServices 0x0000000116cb8cc0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
27 FrontBoardServices 0x0000000116cc17b5 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
28 libdispatch.dylib 0x000000010f87b33d _dispatch_client_callout + 8
29 libdispatch.dylib 0x000000010f8809f3 _dispatch_block_invoke_direct + 592
30 FrontBoardServices 0x0000000116ced498 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
31 FrontBoardServices 0x0000000116ced14e -[FBSSerialQueue _performNext] + 464
32 FrontBoardServices 0x0000000116ced6bd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
33 CoreFoundation 0x000000010efe2101 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
34 CoreFoundation 0x000000010f081f71 __CFRunLoopDoSource0 + 81
35 CoreFoundation 0x000000010efc6a19 __CFRunLoopDoSources0 + 185
36 CoreFoundation 0x000000010efc5fff __CFRunLoopRun + 1279
37 CoreFoundation 0x000000010efc5889 CFRunLoopRunSpecific + 409
38 GraphicsServices 0x000000010fed99c6 GSEventRunModal + 62
39 UIKit 0x000000010b09a5d6 UIApplicationMain + 159
40 0x000000010590c331 main + 65
41 libdyld.dylib 0x000000010f8f7d81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Since you have autorelease in your MainSectionsController code I assume that you don't use ARC there. I highly recommend upgrading the code of MainSectionsController and NavigationViewController to ARC. This prevents accidental overreleases that might cause issues like this one.
In addition I'd recommend to move self.viewControllers assignment from the constructor to viewDidLoad if possible.
Im trying to create a New UISPlitViewController and display it instead of current ViewController, but for some reason it's not working, it says:
-[UISplitViewController navigationBar]: unrecognized selector sent to instance
this is the code
- (IBAction)openDocuments:(id)sender {
UINavigationController *leftNavController;
UINavigationController *rightNavController;
MenuDocumentsVC *masterVC = [self.storyboard instantiateViewControllerWithIdentifier:#"MenuDocumentsVC"];
masterVC.title = #" ";
ContentDocumentsVC *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ContentDocumentsVC"];
detailVC.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:LOGO_COMPANY]];
masterVC.delegate = detailVC;
leftNavController = [[UINavigationController alloc] initWithRootViewController:masterVC];
rightNavController = [[UINavigationController alloc] initWithRootViewController:detailVC];
leftNavController.toolbarHidden = FALSE;
rightNavController.toolbarHidden = FALSE;
leftNavController.navigationBar.translucent = FALSE;
rightNavController.navigationBar.translucent = FALSE;
leftNavController.toolbar.translucent = FALSE;
rightNavController.toolbar.translucent = FALSE;
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:leftNavController, rightNavController, nil];
splitViewController.delegate = (id)detailVC;
if ([splitViewController respondsToSelector:#selector(setPresentsWithGesture:)]) {
[splitViewController setPresentsWithGesture:NO];
}
splitViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[UIView transitionWithView:self.view.window
duration:0.5
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.view.window.rootViewController = splitViewController;
} completion:^(BOOL finished) {
}];
}
how to make it work properly??
Exception
2015-01-05 11:01:47.402 myapp[3454:607] -[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00
2015-01-05 11:01:47.406 myapp[3454:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISplitViewController navigationBar]: unrecognized selector sent to instance 0x7b961f00'
*** First throw call stack:
(
0 CoreFoundation 0x010a21e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00a718e5 objc_exception_throw + 44
2 CoreFoundation 0x0113f243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0109250b ___forwarding___ + 1019
4 CoreFoundation 0x010920ee _CF_forwarding_prep_0 + 14
5 eOpenRoad 0x00056d7d +[Functions setNavigationBarControllerToHexColor:] + 333
6 eOpenRoad 0x0004fa15 -[ContentDocumentsVC viewWillAppear:] + 69
7 UIKit 0x0163e04b -[UIViewController _setViewAppearState:isAnimating:] + 448
8 UIKit 0x0163e548 -[UIViewController __viewWillAppear:] + 114
9 UIKit 0x01660c25 -[UINavigationController _startTransition:fromViewController:toViewController:] + 800
10 UIKit 0x016618cc -[UINavigationController _startDeferredTransitionIfNeeded:] + 645
11 UIKit 0x016624e9 -[UINavigationController __viewWillLayoutSubviews] + 57
12 UIKit 0x017a30d1 -[UILayoutContainerView layoutSubviews] + 213
13 UIKit 0x0158a964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
14 libobjc.A.dylib 0x00a8382b -[NSObject performSelector:withObject:] + 70
15 QuartzCore 0x001ea45a -[CALayer layoutSublayers] + 148
16 QuartzCore 0x001de244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
17 QuartzCore 0x001ea3a5 -[CALayer layoutIfNeeded] + 160
18 UIKit 0x0164cae3 -[UIViewController window:setupWithInterfaceOrientation:] + 304
19 UIKit 0x01562aa7 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
20 UIKit 0x01561646 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
21 UIKit 0x01561518 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
22 UIKit 0x015615a0 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
23 UIKit 0x0156063a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
24 UIKit 0x0156059c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
25 UIKit 0x015612f3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
26 UIKit 0x015648e6 -[UIWindow setDelegate:] + 449
27 UIKit 0x0163eb77 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
28 UIKit 0x0155a474 -[UIWindow addRootViewControllerViewIfPossible] + 591
29 UIKit 0x0155ac84 -[UIWindow setRootViewController:] + 960
30 eOpenRoad 0x0005c5ec +[Functions openContentInWindowWithParameters:insideOfNavigationController:] + 7804
31 eOpenRoad 0x0001f42b -[ViewController openDocuments:] + 555
32 libobjc.A.dylib 0x00a83880 -[NSObject performSelector:withObject:withObject:] + 77
33 UIKit 0x0151d3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
34 UIKit 0x0151d345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
35 UIKit 0x0161ebd1 -[UIControl sendAction:to:forEvent:] + 66
36 UIKit 0x0161efc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
37 UIKit 0x0161e243 -[UIControl touchesEnded:withEvent:] + 641
38 UIKit 0x0155cddd -[UIWindow _sendTouchesForEvent:] + 852
39 UIKit 0x0155d9d1 -[UIWindow sendEvent:] + 1117
40 UIKit 0x0152f5f2 -[UIApplication sendEvent:] + 242
41 UIKit 0x01519353 _UIApplicationHandleEventQueue + 11455
42 CoreFoundation 0x0102b77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
43 CoreFoundation 0x0102b10b __CFRunLoopDoSources0 + 235
44 CoreFoundation 0x010481ae __CFRunLoopRun + 910
45 CoreFoundation 0x010479d3 CFRunLoopRunSpecific + 467
46 CoreFoundation 0x010477eb CFRunLoopRunInMode + 123
47 GraphicsServices 0x03ae75ee GSEventRunModal + 192
48 GraphicsServices 0x03ae742b GSEventRun + 104
49 UIKit 0x0151bf9b UIApplicationMain + 1225
50 eOpenRoad 0x00051e3d main + 141
51 libdyld.dylib 0x036b76d9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
From provided log I can say that problem lie in [ContentDocumentsVC viewWillAppear:] where you set color to navigation bar with category method setNavigationBarControllerToHexColor: but looks like you call this method on wrong controller.
I try to present a UIImagePickerController from rect using this code:
UIImagePickerController* imgPickerController = [[UIImagePickerController alloc] init];
imgPickerController.delegate = self;
imgPickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgPickerController.mediaTypes = [[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil];
imgPickerController.allowsEditing = NO;
_popover = [[UIPopoverController alloc] initWithContentViewController:imgPickerController];
[_popover setDelegate:self];
[_popover presentPopoverFromRect:CGRectMake(195, 55, 70, 64) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
But sometimes crash happends... NO always, sometimes run, sometimes crash...
This is the crash LOG:
Thread 0: Crashed: com.apple.main-thread
0 CoreText 0x2e4c0d1e TComponentFont::GetRawBoundingBox() const + 13
1 CoreText 0x2e4b3ba7 TBaseFont::CalculateFontMetrics(bool) const + 110
2 CoreText 0x2e4b3ba7 TBaseFont::CalculateFontMetrics(bool) const + 110
3 CoreText 0x2e4c0d0b TComponentFont::CalculateFontMetrics(bool) const + 34
4 CoreText 0x2e4b39fd TBaseFont::InitFontMetrics() const + 44
5 CoreText 0x2e4b3839 TBaseFont::GetStrikeMetrics(float, CGAffineTransform const*, bool) const + 104
6 CoreText 0x2e4b3603 TFont::InitStrikeMetrics() const + 38
7 CoreText 0x2e4b35b9 CTFontGetAscent + 92
8 GraphicsServices 0x32a17245 GSFontEnsureExtraData + 228
9 GraphicsServices 0x32a19361 GSFontGetLatin1LayoutInfo + 44
10 UIFoundation 0x359a252d -[UIFont(UIFont_AttributedStringDrawing) _getLatin1GlyphMapping:andAdvanceMapping:] + 12
11 UIFoundation 0x35978e61 __NSStringDrawingEngine + 3784
12 UIFoundation 0x3597df7f -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 898
13 UIKit 0x3085dcab -[UILabel _updateScaledMetricsForRect:] + 594
14 UIKit 0x306023d3 -[UILabel setAdjustsFontSizeToFitWidth:] + 206
15 PhotosUI 0x3466608b -[PUFlatWhiteInterfaceTheme configureAlbumListSubtitleLabel:]
16 PhotosUI 0x345bc141 +[PUAlbumListCellContentView _updateLabelGlobalCachedSizes]
17 libobjc.A.dylib 0x38588231 _class_initialize + 572
18 libobjc.A.dylib 0x3858f7a7 lookUpImpOrForward + 130
19 libobjc.A.dylib 0x38587feb _class_lookupMethodAndLoadCache3 + 34
20 libobjc.A.dylib 0x38587db9 _objc_msgSend_uncached + 24
21 PhotosUI 0x345bb059 -[PUAlbumListTableViewController tableView:cellForRowAtIndexPath:]
22 UIKit 0x3069aa5b -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 410
23 UIKit 0x30642e7d -[UITableView _updateVisibleCellsNow:] + 1804
24 UIKit 0x30642699 -[UITableView layoutSubviews] + 184
25 UIKit 0x30568da3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
26 QuartzCore 0x301efc6b -[CALayer layoutSublayers] + 142
27 QuartzCore 0x301eb47b CA::Layer::layout_if_needed(CA::Transaction*) + 350
28 UIKit 0x3057dc1b -[UIView(Hierarchy) layoutBelowIfNeeded] + 530
29 PhotosUI 0x3467ec55 -[PUAbstractAlbumListViewController viewDidLayoutSubviews]
30 UIKit 0x30568e79 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 560
31 QuartzCore 0x301efc6b -[CALayer layoutSublayers] + 142
32 QuartzCore 0x301eb47b CA::Layer::layout_if_needed(CA::Transaction*) + 350
33 QuartzCore 0x301eb30d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
34 QuartzCore 0x301ead1f CA::Context::commit_transaction(CA::Transaction*) + 230
35 QuartzCore 0x301eab2f CA::Transaction::commit() + 314
36 UIKit 0x305610c3 _afterCACommitHandler + 126
37 CoreFoundation 0x2ddc11cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
38 CoreFoundation 0x2ddbeb71 __CFRunLoopDoObservers + 284
39 CoreFoundation 0x2ddbeeb3 __CFRunLoopRun + 730
40 CoreFoundation 0x2dd29c27 CFRunLoopRunSpecific + 522
41 CoreFoundation 0x2dd29a0b CFRunLoopRunInMode + 106
42 GraphicsServices 0x32a1d283 GSEventRunModal + 138
43 UIKit 0x305cd049 UIApplicationMain + 1136
44 Puzz! 0x00032665 main (main.m:16)
Thanks!
EDIT
Finally, I decided use a AssetsLibrary framework to create a custom UIImagePickerController using this MyImagePicker sample:
https://developer.apple.com/library/ios/samplecode/myimagepicker/Introduction/Intro.html
Here is the code. I tried to create a object which includes the name, size and image(get from the resource) and then I add that object into NSMutableArray in order to show those object in NSTableView. However, after I run the code, I did get the correct counts of object in NSMutableArray and correct information in each object(name,size,image), but it still gives me error. Could you guys help me. I am a new Mac developer. Thanks !!
Here is the code:
#implementation AppDelegate{
NSMutableArray* _tableContents;
}
-(void)awakeFromNib{
NSString* imagePath = #"USB.png";
NSString* mountPath = #"/Volumes";
_tableContents = [[NSMutableArray alloc]init];
for(mountPath in [[NSWorkspace sharedWorkspace]mountedLocalVolumePaths])
{
if(0==[mountPath rangeOfString:#"/Volumes/"].location)
{
NSString* USBpath = [[[NSWorkspace sharedWorkspace]mountedLocalVolumePaths]objectAtIndex:count];
//get the name of USB drive
NSString* nameOfUSB = [USBpath substringFromIndex:9];
//get the size of USB drive
NSNumber *volumeSize;
NSURL *mountPathPicked = [NSURL fileURLWithPath:mountPath];
if([mountPathPicked getResourceValue:&volumeSize forKey:NSURLVolumeTotalCapacityKey error:nil])
{
NSDictionary *obj = #{#"name":nameOfUSB,
#"image":[NSImage imageNamed:imagePath],
#"size":volumeSize
};
//after I call the following line, it will give me error !!
[_tableContents addObject:obj];
}
}
count ++;
}
}
//I also use the following two methods in order to show the name, and image in NSTableView
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
return [_tableCountents count];
}
-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
NSDictionary *flag = _tableContents[row];
NSString *identifier = [tableColumn identifier];//call different col we need identifier
if([identifier isEqualToString:#"MainCell"])
{
NSTableCellView *cellView = [tableView makeViewWithIdentifier:#"MainCell" owner:self];//give back specific cell named mainCell
[cellView.textField setStringValue:flag[#"name"]];
[cellView.imageView setImage:flag[#"image"]];
return cellView;
}
return nil;
}
There is no connection problems in GUI. And here is the error message:
2013-04-25 01:16:41.321 NAMEOFPROJECT[8243:303] An uncaught exception was raised
2013-04-25 01:16:41.322 NAMEOFPROJECT[8243:303] *** -[__NSArrayI objectAtIndex:]: index 7 beyond bounds [0 .. 3]
2013-04-25 01:16:41.329 NAMEOFPROJECT[8243:303] (
0 CoreFoundation 0x00007fff9147cb06 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff900c03f0 objc_exception_throw + 43
2 CoreFoundation 0x00007fff9142fb53 -[__NSArrayI objectAtIndex:] + 163
3 CDTOANYDRIVE 0x00000001000011d6 -[AppDelegate DetectingUSBDrives] + 710
4 CDTOANYDRIVE 0x0000000100000efb -[AppDelegate awakeFromNib] + 43
5 AppKit 0x00007fff899631a8 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1234
6 AppKit 0x00007fff89b79976 -[NSNib _instantiateNibWithExternalNameTable:] + 610
7 AppKit 0x00007fff89b7a41a -[NSNib instantiateNibWithExternalNameTable:] + 17
8 AppKit 0x00007fff89b262b4 -[NSTableRowData _unarchiveViewWithIdentifier:owner:] + 520
9 CDTOANYDRIVE 0x000000010000174b -[AppDelegate tableView:viewForTableColumn:row:] + 219
10 AppKit 0x00007fff89b279a2 -[NSTableRowData _addViewToRowView:atColumn:row:] + 324
11 AppKit 0x00007fff89b2766f -[NSTableRowData _addViewsToRowView:atRow:] + 151
12 AppKit 0x00007fff89b25c05 -[NSTableRowData _addRowViewForVisibleRow:withPriorView:] + 415
13 AppKit 0x00007fff89b2598a -[NSTableRowData _addRowViewForVisibleRow:withPriorRowIndex:inDictionary:withRowAnimation:] + 272
14 AppKit 0x00007fff89b24c59 -[NSTableRowData _unsafeUpdateVisibleRowEntries] + 740
15 AppKit 0x00007fff89b247f1 -[NSTableRowData updateVisibleRowViews] + 119
16 AppKit 0x00007fff89afc5d7 -[NSTableView layout] + 165
17 AppKit 0x00007fff89aafe95 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 112
18 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
19 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
20 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
21 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
22 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
23 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
24 CoreFoundation 0x00007fff914754a6 __NSArrayEnumerate + 582
25 AppKit 0x00007fff89aafff6 -[NSView _layoutSubtreeHeedingRecursionGuard:] + 465
26 AppKit 0x00007fff89aafd2e -[NSView layoutSubtreeIfNeeded] + 615
27 AppKit 0x00007fff89aab4dc -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 201
28 AppKit 0x00007fff899d96a8 -[NSView _layoutAtWindowLevelIfNeeded] + 99
29 AppKit 0x00007fff899d8fe6 -[NSView _sendViewWillDrawInRect:clipRootView:] + 87
30 AppKit 0x00007fff899a59b1 -[NSView displayIfNeeded] + 1044
31 AppKit 0x00007fff89a62a48 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 1377
32 AppKit 0x00007fff89a62068 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 940
33 AppKit 0x00007fff89a61c4f -[NSWindow orderWindow:relativeTo:] + 159
34 AppKit 0x00007fff89963266 -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1424
35 AppKit 0x00007fff8994214d loadNib + 317
36 AppKit 0x00007fff89941679 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
37 AppKit 0x00007fff899414ae -[NSBundle(NSNibLoading) loadNibNamed:owner:topLevelObjects:] + 200
38 AppKit 0x00007fff8994128e +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 360
39 AppKit 0x00007fff8993da2f NSApplicationMain + 398
40 CDTOANYDRIVE 0x0000000100000e82 main + 34
41 libdyld.dylib 0x00007fff9385a7e1 start + 0
42 ??? 0x0000000000000003 0x0 + 3
)
And the above error shows twice !!
I have tried your code in a mini-app and It works fine. There are few things that I might highlight:
Your exception occurs in the method DetectingUSBDrives, for which we don't have any code. I'm assuming that you have pasted the code in the awakeFromNib method.
You are using count as an index. Is this varibale initialized at zero?
The fact that the error appears twice suggests that your cell views hold a reference to your app delegate, which means that awakeFromNib is called once for each view creation. This can create many problem since you are initializing _tableOfContents there. You might want to move all that code to the init method instead.
When I run the following Code it crashes at the last line. I don't have any idea why. This function gets called in awakeFromNib.
- (void)setMotdText:(NSString *)text
{
NSString *boldFontName = [[NSFont boldSystemFontOfSize:12] fontName];
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:text];
[attrstr beginEditing];
[attrstr addAttribute:NSFontAttributeName value:boldFontName range:NSMakeRange(0, 16)];
[attrstr endEditing];
[self.motdTextView.textStorage setAttributedString:attrstr];
}
I get this crash log:
2012-06-22 11:32:22.348 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.349 MSM-Plan[20785:403] An uncaught exception was raised
2012-06-22 11:32:22.349 MSM-Plan[20785:403] -[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380
2012-06-22 11:32:22.351 MSM-Plan[20785:403] (
0 CoreFoundation 0x00007fff8a5bef56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8ae19d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8a64b1be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8a5abe23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8a5abc38 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8e0b060c -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixFontAttributeInRange:] + 1249
6 AppKit 0x00007fff8e0afeb7 -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixAttributesInRange:] + 64
7 AppKit 0x00007fff8e19b521 -[NSTextStorage processEditing] + 107
8 AppKit 0x00007fff8e0c2564 -[NSTextStorage edited:range:changeInLength:] + 385
9 Foundation 0x00007fff8d6f4497 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 328
10 AppKit 0x00007fff8e1dfd19 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 81
11 MSM-Plan 0x000000010206af5a -[MSM_PlanAppDelegate setMotdText:] + 314
12 MSM-Plan 0x000000010206c455 -[MSM_PlanAppDelegate awakeFromNib] + 1701
13 CoreFoundation 0x00007fff8a5b5fb1 -[NSObject performSelector:] + 49
14 CoreFoundation 0x00007fff8a5b5f32 -[NSSet makeObjectsPerformSelector:] + 274
15 AppKit 0x00007fff8e0369ff -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
16 AppKit 0x00007fff8e02cf73 loadNib + 322
17 AppKit 0x00007fff8e02c470 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
18 AppKit 0x00007fff8e02c38b +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
19 AppKit 0x00007fff8e02c2ce +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
20 AppKit 0x00007fff8e29d06f NSApplicationMain + 398
21 MSM-Plan 0x000000010206adf2 main + 34
22 MSM-Plan 0x000000010206adc4 start + 52
)
2012-06-22 11:32:22.416 MSM-Plan[20785:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isDefaultFace]: unrecognized selector sent to instance 0x7fff79b9f380'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8a5bef56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff8ae19d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8a64b1be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8a5abe23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8a5abc38 _CF_forwarding_prep_0 + 232
5 AppKit 0x00007fff8e0b060c -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixFontAttributeInRange:] + 1249
6 AppKit 0x00007fff8e0afeb7 -[NSMutableAttributedString(NSMutableAttributedStringKitAdditions) fixAttributesInRange:] + 64
7 AppKit 0x00007fff8e19b521 -[NSTextStorage processEditing] + 107
8 AppKit 0x00007fff8e0c2564 -[NSTextStorage edited:range:changeInLength:] + 385
9 Foundation 0x00007fff8d6f4497 -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:] + 328
10 AppKit 0x00007fff8e1dfd19 -[NSConcreteTextStorage replaceCharactersInRange:withAttributedString:] + 81
11 MSM-Plan 0x000000010206af5a -[MSM_PlanAppDelegate setMotdText:] + 314
12 MSM-Plan 0x000000010206c455 -[MSM_PlanAppDelegate awakeFromNib] + 1701
13 CoreFoundation 0x00007fff8a5b5fb1 -[NSObject performSelector:] + 49
14 CoreFoundation 0x00007fff8a5b5f32 -[NSSet makeObjectsPerformSelector:] + 274
15 AppKit 0x00007fff8e0369ff -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1245
16 AppKit 0x00007fff8e02cf73 loadNib + 322
17 AppKit 0x00007fff8e02c470 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 217
18 AppKit 0x00007fff8e02c38b +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 141
19 AppKit 0x00007fff8e02c2ce +[NSBundle(NSNibLoading) loadNibNamed:owner:] + 364
20 AppKit 0x00007fff8e29d06f NSApplicationMain + 398
21 MSM-Plan 0x000000010206adf2 main + 34
22 MSM-Plan 0x000000010206adc4 start + 52
)
terminate called throwing an exception(lldb)
Has anybody an idea? If I call it with a NSAttributedString-Object thereĀ“s no error.
I had to change the first line to:
NSFont *boldFont = [NSFont boldSystemFontOfSize:12];
Now it works, because the value attribute requires a NSFont-Object and not a NSString with the fonts name.
This is the working Code:
- (void)setMotdText:(NSString *)text
{
NSFont *boldFont = [NSFont boldSystemFontOfSize:12];
NSMutableAttributedString *attrstr = [[NSMutableAttributedString alloc] initWithString:text];
[attrstr beginEditing];
[attrstr addAttribute:NSFontAttributeName value:boldFont range:NSMakeRange(0, 16)];
[attrstr endEditing];
[self.motdTextView.textStorage setAttributedString:attrstr];
}