I try to do a simple program in cocoa, a NSTabVew with 2 items, in the first item I set a content to a string var, in the second tab I display this value. I create two Object class (Prima and Seconda), than I add 2 object in IB setting like Prima and Seconda
Prima.m
- (IBAction) salva:(id) sender{
nome = [field stringValue];
NSLog(#"%#",nome);
}
Seconda.m
- (IBAction) visualizza:(id) sender{
NSString *dato;
Prima *prima = [[Prima alloc] init];
dato = prima.nome;
[label setStringValue:dato];
}
when I run the program I get this error:
2011-10-03 11:42:43.511 Prova[44622:707] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1138/AppKit.subproj/NSCell.m:1564
2011-10-03 11:42:43.511 Prova[44622:707] Invalid parameter not satisfying: aString != nil
2011-10-03 11:42:43.513 Prova[44622:707] (
0 CoreFoundation 0x00007fff8d497986 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff90ed9d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d4977ba +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8cce914f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 169
4 AppKit 0x00007fff88957685 -[NSCell _objectValue:forString:errorDescription:] + 160
5 AppKit 0x00007fff889575df -[NSCell _objectValue:forString:] + 19
6 AppKit 0x00007fff88957545 -[NSCell setStringValue:] + 41
7 AppKit 0x00007fff88a58039 -[NSControl setStringValue:] + 115
8 Prova 0x0000000100001365 -[Seconda visualizza:] + 133
9 CoreFoundation 0x00007fff8d48711d -[NSObject performSelector:withObject:] + 61
10 AppKit 0x00007fff88a3f852 -[NSApplication sendAction:to:from:] + 139
11 AppKit 0x00007fff88a3f784 -[NSControl sendAction:to:] + 88
12 AppKit 0x00007fff88a3f6af -[NSCell _sendActionFrom:] + 137
13 AppKit 0x00007fff88a3eb7a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
14 AppKit 0x00007fff88abe57c -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
15 AppKit 0x00007fff88a3d786 -[NSControl mouseDown:] + 786
16 AppKit 0x00007fff88a0866e -[NSWindow sendEvent:] + 6280
17 AppKit 0x00007fff889a0f19 -[NSApplication sendEvent:] + 5665
18 AppKit 0x00007fff8893742b -[NSApplication run] + 548
19 AppKit 0x00007fff88bb552a NSApplicationMain + 867
20 Prova 0x0000000100000f92 main + 34
21 Prova 0x0000000100000f64 start + 52
22 ??? 0x0000000000000001 0x0 + 1
)
where is the error for you?
It seems that dato is nil, which (based on what you've given us) is probably because things aren't hooked up right in the XIB. Without more information I can't say more.
Related
I have a function:
NSTimer *learnUSBTimer=nil;
- (void)showUSBWindow:(id)sender {
[self updateDeviceButton:#"Cancel"];
[self hideDeviceClearButton:TRUE];
[selectedDeviceField setStringValue:#"Insert the USB device..."];
learnUSBMode=1;
if(learnUSBTimer)
{
if([learnUSBTimer isValid])[learnUSBTimer invalidate];
learnUSBTimer=nil;
}
}
And it seems my message sent to the timer object is being sent to the UI object:
2018-02-19 14:02:34.649581-0500 TokenLock[4068:819373] -[NSBox isValid]: unrecognized selector sent to instance 0x60000016bc40
2018-02-19 14:02:34.649691-0500 TokenLock[4068:819373] [General] -[NSBox isValid]: unrecognized selector sent to instance 0x60000016bc40
2018-02-19 14:02:34.651799-0500 TokenLock[4068:819373] [General] (
0 CoreFoundation 0x00007fff4f33833b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff7607c942 objc_exception_throw + 48
2 CoreFoundation 0x00007fff4f3cf5e4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff4f2aff03 ___forwarding___ + 1443
4 CoreFoundation 0x00007fff4f2af8d8 _CF_forwarding_prep_0 + 120
5 TokenLock 0x0000000100014cdc -[AppController showUSBWindow:] + 252
6 AppKit 0x00007fff4d02375a -[NSApplication(NSResponder) sendAction:to:from:] + 312
7 AppKit 0x00007fff4cac9933 -[NSControl sendAction:to:] + 86
8 AppKit 0x00007fff4cac985b __26-[NSCell _sendActionFrom:]_block_invoke + 136
9 AppKit 0x00007fff4cac9761 -[NSCell _sendActionFrom:] + 183
10 AppKit 0x00007fff4cb0aa18 -[NSButtonCell _sendActionFrom:] + 97
11 AppKit 0x00007fff4cac7fca -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438
12 AppKit 0x00007fff4cb0a75f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777
13 AppKit 0x00007fff4cac6a64 -[NSControl mouseDown:] + 965
14 AppKit 0x00007fff4d1c2959 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891
15 AppKit 0x00007fff4d1bf5b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359
16 AppKit 0x00007fff4d1be85c -[NSWindow(NSEventRouting) sendEvent:] + 497
17 AppKit 0x00007fff4d01f617 -[NSApplication(NSEvent) sendEvent:] + 307
18 AppKit 0x00007fff4c880d9d -[NSApplication run] + 812
19 AppKit 0x00007fff4c84ff1a NSApplicationMain + 804
20 TokenLock 0x0000000100001ea1 main + 97
21 TokenLock 0x0000000100001e34 start + 52
)
I dont understand how my NSTimer is being somehow assigned to the UI Box being clicked to execute the function?
It seems that there will be some memory management issue in your code. And the objects are not properly allocated/ deallocated or not initialised deinitialised properly.
So to solve this issue just run your code by enabling zombies into your project target settings.
It turns out this timer fires once. I was not setting it to nil in that code and so it became essentially an orphan because the system released the actual timer object after.
Setting it to nil on firing fixes the issue.
I have 3 NSToolbarItems and the first one works just fine, the other two, each time I select them throw
[16392:513506] -[NSToolbarItem isEqualToString:]: unrecognized selector sent to instance 0x6080001203c0
2015-05-26 19:59:26.871 MyApp[16392:513506] (
0 CoreFoundation 0x00007fff89f9703c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8a40176e objc_exception_throw + 43
2 CoreFoundation 0x00007fff89f9a0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff89edfe24 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff89edf998 _CF_forwarding_prep_0 + 120
5 AppKit 0x00007fff9649d74e +[NSToolbar _shouldIgnoreItemIdentifier:] + 35
6 AppKit 0x00007fff9649d6f7 removeIgnoredIdentifiers + 89
7 AppKit 0x00007fff9675e526 -[NSToolbar selectableItemIdentifiers] + 224
8 AppKit 0x00007fff9675e411 -[NSToolbar _isSelectableItemIdentifier:] + 34
9 AppKit 0x00007fff9675e385 -[NSToolbar setSelectedItemIdentifier:] + 79
10 AppKit 0x00007fff96654f3c -[NSToolbarItemViewer mouseDown:] + 4951
11 AppKit 0x00007fff96bc52fc -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125
12 AppKit 0x00007fff96554d76 -[NSWindow sendEvent:] + 470
13 AppKit 0x00007fff96551312 -[NSApplication sendEvent:] + 2504
14 AppKit 0x00007fff9647ac68 -[NSApplication run] + 711
15 AppKit 0x00007fff963f7354 NSApplicationMain + 1832
16 IPLocation 0x000000010001769d main + 109
17 libdyld.dylib 0x00007fff96ffd5c9 start + 1
18 ??? 0x0000000000000003 0x0 + 3
)
I tried disconnecting and reconnecting them from the storyboard,but nothing changed. The IBAction doesn't even get called.
My ViewController
func toolbarSelectableItemIdentifiers(toolbar: NSToolbar) -> [AnyObject] {
// let array = toolbar.items.filter { contains(Identifier.allValues, $0.itemIdentifier ) }//wrong!
return Identifier.allValues
}
The delegate just needed the name of the identifiers, not the selectable items themselves.
I have a NSTableView that is populated by an array called tableArray. I have a button that is supposed to remove the selected item from the array. In my removeItem: method:
[tableArray removeObjectAtIndex:[tableView selectedRow];
[tableView reloadData];
But I get the error:
2015-05-13 18:16:45.283 FileShedb1.0[979:303] *** -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 0]
2015-05-13 18:16:45.288 FileShedb1.0[979:303] (
0 CoreFoundation 0x00007fff8d35ff56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff93119d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d2ed392 -[__NSArrayM objectAtIndex:] + 274
3 FileShedb1.0 0x00000001000028a9 -[MPOMainWindowController tableViewSelectionDidChange:] + 201
4 Foundation 0x00007fff8cca0d0e __-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_1 + 47
5 CoreFoundation 0x00007fff8d3087ba _CFXNotificationPost + 2634
6 Foundation 0x00007fff8cc8cfc3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 65
7 AppKit 0x00007fff8ab10049 -[NSTableView _sendSelectionChangedNotificationForRows:columns:] + 203
8 AppKit 0x00007fff8aae6b0a -[NSTableView _enableSelectionPostingAndPost] + 425
9 AppKit 0x00007fff8aadcd75 -[NSTableView _tileAndRedisplayAll] + 358
10 FileShedb1.0 0x00000001000027bc -[MPOMainWindowController removeFile:] + 188
11 CoreFoundation 0x00007fff8d34f70d -[NSObject performSelector:withObject:] + 61
12 AppKit 0x00007fff8aaa98ca -[NSApplication sendAction:to:from:] + 139
13 AppKit 0x00007fff8aaa97fe -[NSControl sendAction:to:] + 88
14 AppKit 0x00007fff8aaa9729 -[NSCell _sendActionFrom:] + 137
15 AppKit 0x00007fff8aaa8bec -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
16 AppKit 0x00007fff8ab28b74 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
17 AppKit 0x00007fff8aaa77f6 -[NSControl mouseDown:] + 786
18 AppKit 0x00007fff8aa72c98 -[NSWindow sendEvent:] + 6306
19 AppKit 0x00007fff8aa0c3a5 -[NSApplication sendEvent:] + 5593
20 AppKit 0x00007fff8a9a2a0e -[NSApplication run] + 555
21 AppKit 0x00007fff8ac1eeac NSApplicationMain + 867
22 FileShedb1.0 0x00000001000014c2 main + 34
23 FileShedb1.0 0x0000000100001494 start + 52
)
Anyone know why i'm getting the error?
If no row is selected, selectedRow row returns -1. Put a check for this.
Checkout apple's documentation.
So I am building an app in cocoa and having a bit of trouble. I want to feed text file names in many different folders to a tableview using an array controller, but it keeps throwing out of bounds errors. Heres a chunk of the code giving me trouble.
[self clear:nil]; // method that clears the NSTableView
NSString *chooserSelection = chooserItems.titleOfSelectedItem; // gets the selected folder from an NSPopUpButton
if (chooserSelection == #"All") {
path = #"/Library/Application Support/File Folder/Files/";
NSArray *folders = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
NSLog(#"\nfolders = %#", folders);
for (int i = 0; i < [folders count]; i++) {
path = #"/Library/Application Support/File Folder/Files/";
NSMutableString *folderNames = [[NSMutableString stringWithString:path] init];
[folderNames insertString:folders[i] atIndex:folderNames.length];
[folderNames insertString:#"/" atIndex:folderNames.length];
NSArray *text = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderNames error:nil];
[myArrayController addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:text[i], #"File Name", nil]];
//This line gives the error
}
}
If I change [folders count] to 1 it shows up in the NSTableView. However on anything past that (additional passes through the for loop) i get an out of bounds error.
2013-02-26 13:17:49.679 AppName[3489:403] *** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]
2013-02-26 13:17:49.683 AppName[3489:403] (
0 CoreFoundation 0x00007fff829b5f56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff84fe6d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8295f370 -[__NSArrayI objectAtIndex:] + 208
3 AppName 0x000000010000159a -[AppDelegate tableView:objectValueForTableColumn:row:] + 106
4 AppKit 0x00007fff840a16e7 -[NSTableView _dataSourceValueForColumn:row:] + 73
5 AppKit 0x00007fff840a1167 -[NSTableView preparedCellAtColumn:row:] + 437
6 AppKit 0x00007fff840b2171 -[NSTableView _drawContentsAtRow:column:withCellFrame:] + 42
7 AppKit 0x00007fff840b05d8 -[NSTableView drawRow:clipRect:] + 1647
8 AppKit 0x00007fff840afdb5 -[NSTableView drawRowIndexes:clipRect:] + 565
9 AppKit 0x00007fff840aded7 -[NSTableView drawRect:] + 1390
10 AppKit 0x00007fff84197382 -[NSView(NSInternal) _recursive:displayRectIgnoringOpacity:inContext:topView:] + 1435
11 AppKit 0x00007fff841b564f __-[NSView(NSLayerKitGlue) drawLayer:inContext:]_block_invoke_1 + 94
12 AppKit 0x00007fff841b52fb -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:] + 2001
13 QuartzCore 0x00007fff82c4a0dc -[CALayer drawInContext:] + 145
14 QuartzCore 0x00007fff82c49225 CABackingStoreUpdate_ + 3221
15 QuartzCore 0x00007fff82c4813a _ZN2CA5Layer8display_Ev + 1086
16 AppKit 0x00007fff841504e6 -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 163
17 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
18 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
19 AppKit 0x00007fff841505fc -[NSView(NSInternal) _recursiveDisplayViewsIntoLayersIfNeeded] + 441
20 AppKit 0x00007fff84150168 -[NSView(NSLayerKitGlue) _drawRectAsLayerTree:] + 128
21 AppKit 0x00007fff8401653e -[NSView _drawRect:clip:] + 4382
22 AppKit 0x00007fff8401406d -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 3020
23 AppKit 0x00007fff84014b5e -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5821
24 AppKit 0x00007fff84012da3 -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 270
25 AppKit 0x00007fff8400e1bb -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 4755
26 AppKit 0x00007fff84006c35 -[NSView displayIfNeeded] + 1676
27 AppKit 0x00007fff84006375 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 648
28 CoreFoundation 0x00007fff829758e7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
29 CoreFoundation 0x00007fff82975846 __CFRunLoopDoObservers + 374
30 CoreFoundation 0x00007fff8294aaf9 __CFRunLoopRun + 825
31 CoreFoundation 0x00007fff8294a486 CFRunLoopRunSpecific + 230
32 AppKit 0x00007fff84459b08 -[NSMenu _internalPerformActionForItemAtIndex:] + 38
33 AppKit 0x00007fff842e86f9 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 138
34 AppKit 0x00007fff841349bb NSSLMMenuEventHandler + 339
35 HIToolbox 0x00007fff89d08234 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1263
36 HIToolbox 0x00007fff89d07840 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 446
37 HIToolbox 0x00007fff89d1e6db SendEventToEventTarget + 76
38 HIToolbox 0x00007fff89d647b5 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 398
39 HIToolbox 0x00007fff89e4be2d SendMenuCommandWithContextAndModifiers + 56
40 HIToolbox 0x00007fff89e935b5 SendMenuItemSelectedEvent + 253
41 HIToolbox 0x00007fff89d5d883 _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 101
42 HIToolbox 0x00007fff89e8bfed _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1660
43 HIToolbox 0x00007fff89e8c2ac _HandlePopUpMenuSelection7 + 621
44 AppKit 0x00007fff842eb3c5 _NSSLMPopUpCarbonMenu3 + 3860
45 AppKit 0x00007fff846990fa _NSPopUpCarbonMenu3 + 39
46 AppKit 0x00007fff842e952a -[NSCarbonMenuImpl popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:] + 322
47 AppKit 0x00007fff844ca1f1 -[NSPopUpButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 564
48 AppKit 0x00007fff840cb7f6 -[NSControl mouseDown:] + 786
49 AppKit 0x00007fff84096c98 -[NSWindow sendEvent:] + 6306
50 AppKit 0x00007fff840303a5 -[NSApplication sendEvent:] + 5593
51 AppKit 0x00007fff83fc6a0e -[NSApplication run] + 555
52 AppKit 0x00007fff84242eac NSApplicationMain + 867
53 AppName 0x0000000100001152 main + 34
54 AppName 0x0000000100001124 start + 52
)
I can also more the addObject line to the line below the for loop which will display the filename of the last file. But I cannot figure out where the out of bounds error is coming from.
You are using the index i first for the count of folders in path, and then for the count of files in that respective folder. So you are depending on there being at least as many files in folder N as the number of N.
For example if you have three folders
folder0
folder1
folder2
then when you iterate over folder2 (i=2), there had better be at least 3 items in the folder as you are accessing item 3 (text[2]). When there are fewer items, you will get that out-of-bounds error.
You probably mean to do something like this:
NSMutableDictionary* dict =
[NSMutableDictionary dictionaryWithObjectsAndKeys:text, folders[i], nil];
That will get you an array of dictionaries. Each dictionary has a single key (the name of the folder,) and a single value (an array of filenames).
You could simplify your data structure further by flattening this to a single dictionary (not inside an array). Each key is a folder name, each value is the array of filenames.
I have a subclass of NSDocument that crashes whenever I use [self close] to avoid the default 'save' dialog for new documents:
2013-02-25 15:23:06.338 MyApp[692:403] An uncaught exception was raised
2013-02-25 15:23:06.338 MyApp[692:403] NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.
2013-02-25 15:23:06.356 MyApp[692:403] (
0 CoreFoundation 0x00007fff8b2cdf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff88c00d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8b2cdd8a +[NSException raise:format:arguments:] + 106
3 CoreFoundation 0x00007fff8b2cdd14 +[NSException raise:format:] + 116
4 AppKit 0x00007fff858e0c34 -[NSWindow _newFirstResponderAfterResigning] + 164
5 AppKit 0x00007fff85882c8a -[NSTextView(NSSharing) resignFirstResponder] + 54
6 AppKit 0x00007fff8536dd79 -[NSWindow makeFirstResponder:] + 429
7 AppKit 0x00007fff85488dfb -[NSWindow dealloc] + 802
8 AppKit 0x00007fff8528b955 -[NSWindow release] + 535
9 AppKit 0x00007fff858b541c __destroy_helper_block_4 + 26
10 libsystem_blocks.dylib 0x00007fff8702b174 _Block_release + 181
11 libdispatch.dylib 0x00007fff84ab28f2 _dispatch_main_queue_callback_4CF + 308
12 CoreFoundation 0x00007fff8b262e7c __CFRunLoopRun + 1724
13 CoreFoundation 0x00007fff8b262486 CFRunLoopRunSpecific + 230
14 HIToolbox 0x00007fff8d64e2bf RunCurrentEventLoopInMode + 277
15 HIToolbox 0x00007fff8d65556d ReceiveNextEventCommon + 355
16 HIToolbox 0x00007fff8d6553fa BlockUntilNextEventMatchingListInMode + 62
17 AppKit 0x00007fff85252779 _DPSNextEvent + 659
18 AppKit 0x00007fff8525207d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
19 AppKit 0x00007fff8524e9b9 -[NSApplication run] + 470
20 AppKit 0x00007fff854caeac NSApplicationMain + 867
21 MyApp 0x00000001059098d2 main + 34
22 MyApp 0x00000001059098a4 start + 52
23 ??? 0x0000000000000003 0x0 + 3
)
Has anyone seen this before or can anyone suggest a better/proper way to close an NSDocument without the save dialog being shown?
So judging by your followup comments, what you're trying to do is suppress the standard close confirmation sheet under specific circumstances. Some ways to do that:
Adopt autosaving-in-place, which moves away from the ancient paradigm of manually saving documents
Override -[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:] so it tells the delegate "yes, you can close", rather than presenting a sheet
Once a post is made, call [document updateChangeCount: NSChangeCleared] to inform the document that you consider it to be saved