Hello friends I faced problem while creating MAC Application I have two view controllers. when I clicks on button which is placed in first view controller app replace view using below code
- (IBAction)gotoEmployeeView:(id)sender
{
delegate = (AppDelegate *)[[NSApplication sharedApplication]delegate];
secondViewController *employeeVC = [[secondViewController alloc]initWithNibName:#"secondViewController" bundle:nil];
[[delegate.window.contentView animator] replaceSubview:self.view with:secondVC.view];
secondVC.view.frame = ((NSView *)delegate.window.contentView).bounds;
}
now I have one button and I have set click event for this button on second view. below id button click event
- (IBAction)btnClicked:(id)sender
{
NSLog(#"clicked");
}
and when I clicked on it app was crashed. and get below error
2013-08-12 14:33:46.989 Employee Register[1954:303] -[__NSCFString btnClicked:]: unrecognized selector sent to instance 0x10213ace0
2013-08-12 14:33:46.991 Employee Register[1954:303] -[__NSCFString btnClicked:]: unrecognized selector sent to instance 0x10213ace0
2013-08-12 14:33:46.994 Employee Register[1954:303] (
0 CoreFoundation 0x00007fff8d76cf56 __exceptionPreprocess + 198
1 libobjc.A.dylib 0x00007fff80e47d5e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8d7f91be -[NSObject doesNotRecognizeSelector:] + 190
3 CoreFoundation 0x00007fff8d759e23 ___forwarding___ + 371
4 CoreFoundation 0x00007fff8d759c38 _CF_forwarding_prep_0 + 232
5 CoreFoundation 0x00007fff8d75c70d -[NSObject performSelector:withObject:] + 61
6 AppKit 0x00007fff8c5208ca -[NSApplication sendAction:to:from:] + 139
7 AppKit 0x00007fff8c5207fe -[NSControl sendAction:to:] + 88
8 AppKit 0x00007fff8c520729 -[NSCell _sendActionFrom:] + 137
9 AppKit 0x00007fff8c51fbec -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2014
10 AppKit 0x00007fff8c59fb74 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 489
11 AppKit 0x00007fff8c51e7f6 -[NSControl mouseDown:] + 786
12 AppKit 0x00007fff8c4e9c98 -[NSWindow sendEvent:] + 6306
13 AppKit 0x00007fff8c4833a5 -[NSApplication sendEvent:] + 5593
14 AppKit 0x00007fff8c419a0e -[NSApplication run] + 555
15 AppKit 0x00007fff8c695eac NSApplicationMain + 867
16 Employee Register 0x0000000100001342 main + 34
17 Employee Register 0x0000000100001314 start + 52
)
It looks like you're sending a btnClicked message to a NSString object. Can you post the code where you call [... bntClicked] ?
The behaviour you are describing can mean either that the viewController implementing the btnClicked method gets deallocated before the action is called or that the action in interface builder is not set correctly.
You should add a log statement in the dealloc method of the viewController implementing the btnClicked and see that it does not get deallocated before the action is called. If you're using ARC make sure that you have a member data pointing to your view controllers so they don't get released.
Also you should delete the ibaction association in interface builder and do it again making sure that you connect the button to the correct view controller.
Your gotoEmployeeView code looks fine to me.
NOTE : replaceSubview:with: method causes oldView to be released.
Take a look at sample project.
Related
I am trying to use .xib files in iOS10+ in table View Controller again and again to load
static NSString *reuseIdentifier = #"SessionTableViewCellIdentifier";
SessionTableViewCell *cell = (SessionTableViewCell*)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if( !cell )
{
cell = [[[NSBundle mainBundle] loadNibNamed:#"SessionTableViewCell" owner:self options:nil] objectAtIndex:0];
}
It is working fine on Version 9.3 but after some time it gives me exception on iOS 10+
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/srtekappledemo/Library/Developer/CoreSimulator/Devices/1848F1BA-50B8-41AB-8538-CD741BD1A685/data/Containers/Bundle/Application/391AD08C-1DD7-46A0-A4D0-A07274A72241/ACSuccess.app> (loaded)' with name '3pB-ff-s9x-view-jo5-RS-cHl' and directory 'Main.storyboardc''
*** First throw call stack:
(
0 CoreFoundation 0x000000010e08fd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010d6d021e objc_exception_throw + 48
2 CoreFoundation 0x000000010e0f92b5 +[NSException raise:format:] + 197
3 UIKit 0x000000010f342bd2 -[UINib instantiateWithOwner:options:] + 507
4 UIKit 0x000000010f0d69c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
5 UIKit 0x000000010f0d72e7 -[UIViewController loadView] + 177
6 UIKit 0x000000010f0d761c -[UIViewController loadViewIfRequired] + 201
7 UIKit 0x000000010f0de062 -[UIViewController __viewWillAppear:] + 118
8 UIKit 0x000000010f1091d3 -[UINavigationController _startCustomTransition:] + 1290
9 UIKit 0x000000010f119e48 -[UINavigationController _startDeferredTransitionIfNeeded:] + 697
10 UIKit 0x000000010f11afdb -[UINavigationController __viewWillLayoutSubviews] + 58
11 UIKit 0x000000010f311dd7 -[UILayoutContainerView layoutSubviews] + 223
12 UIKit 0x000000010effaab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
13 QuartzCore 0x000000010d02ebf8 -[CALayer layoutSublayers] + 146
14 QuartzCore 0x000000010d022440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
15 QuartzCore 0x000000010d0222be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x000000010cfb0318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
17 QuartzCore 0x000000010cfdd3ff _ZN2CA11Transaction6commitEv + 475
18 UIKit 0x000000010ef607f0 _afterCACommitHandler + 346
19 CoreFoundation 0x000000010e034267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x000000010e0341d7 __CFRunLoopDoObservers + 391
21 CoreFoundation 0x000000010e018f8e __CFRunLoopRun + 1198
22 CoreFoundation 0x000000010e018884 CFRunLoopRunSpecific + 420
23 GraphicsServices 0x0000000111302a6f GSEventRunModal + 161
24 UIKit 0x000000010ef35c68 UIApplicationMain + 159
25 ACSuccess 0x000000010cbc08ff main + 111
26 libdyld.dylib 0x0000000111a7668d start + 1
but there are so many links for it I have tried almost everything, Stated below:
Have you renamed your xib or storyboard file outside Xcode? If so, check everywhere you have a reference to it for inconsistencies. Also be sure you respect the uppercase / lowercase letters anywhere you reference the file since is case sensitive.
Go to Interface Builder, select your View1 ViewController > Utilities Panel > Identity Inspector > check if the Custom Class corresponds to your ViewController Class if you have one (.h and .m files).
Check your target's Build Phases > Copy Bundle Resources and make sure that your xib or storyboard file is added there. If you instantiate your View1 ViewController programmatically and you use xib file check the nib name for typos (remember, is case-sensitive). Also, if you currently append .xib file format to the name, remove the extension because it shouldn't be used. What I mean is this line of code:
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"xibFileName" bundle:nil];
Check the properties of your xib or storyboard file in the file inspector and make sure that your file is linked to your target in the Target Membership selection panel.
Check the properties of the xib or storyboard file in the file inspector and try switching your file Location to Relative to project or Relative to group. See if either way makes a difference.
If you're adding your view controller programmatically in the initWithCoder then you should instantiate it in the viewDidLoad method instead
If nothing from above applies to your situation, you could delete the file from Xcode (select Remove References) and import it again in your project.
Check your Info.plist file. If you use storyboads, you should have an entry like Main storyboard file base name and NOT Main nib file base name. If you use nibs, then is vice-versa. Also check that the file base name corresponds with name of the actual file.
Am I missing memory leak which is creating it this query?
I'm using the NSSavePanel in OS X 10.10 in a sandboxed app to let the user choose the save location of a file (pretty standard), however the app crashes when i call:
NSSavePanel *panel = [NSSavePanel savePanel];
I get this in the debugger:
2014-10-14 18:22:16.019 Farm Hand[2807:942766] an error occurred while attempting to connect to listener 'com.apple.view-bridge': Connection interrupted
2014-10-14 18:22:16.020 Farm Hand[2807:942766] *** Assertion failure in +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:], /SourceCache/ViewBridge/ViewBridge-99/NSXPCSharedListener.m:394
2014-10-14 18:22:16.023 Farm Hand[2807:942766] An uncaught exception was raised
2014-10-14 18:22:16.023 Farm Hand[2807:942766] NSXPCSharedListener unable to create endpoint for listener named com.apple.view-bridge
2014-10-14 18:22:16.023 Farm Hand[2807:942766] (
0 CoreFoundation 0x00007fff8880364c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9390e6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8880342a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8a3a65b9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 ViewBridge 0x00007fff964e40b8 +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:] + 151
5 ViewBridge 0x00007fff964c2981 -[NSRemoteViewBase serviceMarshalConnection] + 286
6 ViewBridge 0x00007fff964c36ae -[NSRemoteViewBase advanceToConfigPhase:awaitingWindowRights:] + 414
7 ViewBridge 0x00007fff964d1f7b -[NSWindowCentricRemoteView advanceToConfigPhase] + 947
8 ViewBridge 0x00007fff964c4223 -[NSRemoteViewBase viewServiceMarshalProxy:withErrorHandler:] + 88
9 ViewBridge 0x00007fff964ba8a8 -[NSRemoteViewBase bridge] + 207
10 AppKit 0x00007fff8e859b9d -[NSVBSavePanel init] + 303
11 AppKit 0x00007fff8e5a8ec1 +[NSSavePanel newRemotePanel] + 301
12 AppKit 0x00007fff8e5a8f53 +[NSSavePanel _crunchyRawUnbonedPanel] + 74
13 Farm Hand 0x000000010009526d __40-[RHFlockHomeViewController exportTable]_block_invoke_3 + 109
14 libdispatch.dylib 0x00000001002202bb _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000010021ad43 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000100229d9f _dispatch_main_queue_callback_4CF + 1370
17 CoreFoundation 0x00007fff88756c59 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x00007fff887132ef __CFRunLoopRun + 2159
19 CoreFoundation 0x00007fff88712838 CFRunLoopRunSpecific + 296
20 HIToolbox 0x00007fff94ec743f RunCurrentEventLoopInMode + 235
21 HIToolbox 0x00007fff94ec71ba ReceiveNextEventCommon + 431
22 HIToolbox 0x00007fff94ec6ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
23 AppKit 0x00007fff8e006821 _DPSNextEvent + 964
24 AppKit 0x00007fff8e005fd0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
25 AppKit 0x00007fff8dff9f73 -[NSApplication run] + 594
26 AppKit 0x00007fff8dfe5424 NSApplicationMain + 1832
27 Farm Hand 0x0000000100010552 main + 34
28 libdyld.dylib 0x00007fff8d7e85c9 start + 1
)
2014-10-14 18:22:16.027 Farm Hand[2807:942766] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSXPCSharedListener unable to create endpoint for listener named com.apple.view-bridge'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8880364c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff9390e6de objc_exception_throw + 43
2 CoreFoundation 0x00007fff8880342a +[NSException raise:format:arguments:] + 106
3 Foundation 0x00007fff8a3a65b9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 ViewBridge 0x00007fff964e40b8 +[NSXPCSharedListener connectionForListenerNamed:fromServiceNamed:] + 151
5 ViewBridge 0x00007fff964c2981 -[NSRemoteViewBase serviceMarshalConnection] + 286
6 ViewBridge 0x00007fff964c36ae -[NSRemoteViewBase advanceToConfigPhase:awaitingWindowRights:] + 414
7 ViewBridge 0x00007fff964d1f7b -[NSWindowCentricRemoteView advanceToConfigPhase] + 947
8 ViewBridge 0x00007fff964c4223 -[NSRemoteViewBase viewServiceMarshalProxy:withErrorHandler:] + 88
9 ViewBridge 0x00007fff964ba8a8 -[NSRemoteViewBase bridge] + 207
10 AppKit 0x00007fff8e859b9d -[NSVBSavePanel init] + 303
11 AppKit 0x00007fff8e5a8ec1 +[NSSavePanel newRemotePanel] + 301
12 AppKit 0x00007fff8e5a8f53 +[NSSavePanel _crunchyRawUnbonedPanel] + 74
13 Farm Hand 0x000000010009526d __40-[RHFlockHomeViewController exportTable]_block_invoke_3 + 109
14 libdispatch.dylib 0x00000001002202bb _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000010021ad43 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000100229d9f _dispatch_main_queue_callback_4CF + 1370
17 CoreFoundation 0x00007fff88756c59 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x00007fff887132ef __CFRunLoopRun + 2159
19 CoreFoundation 0x00007fff88712838 CFRunLoopRunSpecific + 296
20 HIToolbox 0x00007fff94ec743f RunCurrentEventLoopInMode + 235
21 HIToolbox 0x00007fff94ec71ba ReceiveNextEventCommon + 431
22 HIToolbox 0x00007fff94ec6ffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
23 AppKit 0x00007fff8e006821 _DPSNextEvent + 964
24 AppKit 0x00007fff8e005fd0 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
25 AppKit 0x00007fff8dff9f73 -[NSApplication run] + 594
26 AppKit 0x00007fff8dfe5424 NSApplicationMain + 1832
27 Farm Hand 0x0000000100010552 main + 34
28 libdyld.dylib 0x00007fff8d7e85c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is my code in full:
if ([format isEqualToString:#".csv"]) {
loadingBar = [RHLoadingBar loadingBarWithMessage:#"Preparing File..."];
[loadingBar showModally];
[loadingBar start];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *string = [[RHFileController sharedController] CSVTableWithObject:sheepArrayController.arrangedObjects propertyKeys:#[#"tagNumber", #"ukNumber", #"age", #"breed", #"comments"] columnHeaders:#[#"Tag Number", #"UK Number", #"Age", #"Breed", #"Comments"]];
dispatch_async(dispatch_get_main_queue(), ^{
[loadingBar stop];
[loadingBar dismiss];
NSSavePanel *panel = [NSSavePanel savePanel];
[panel beginSheetModalForWindow:[[NSApplication sharedApplication] mainWindow] completionHandler:^(NSInteger result) {
}];
});
});
}
Is this a known bug or is it something in my code? If it's a known bug can I get round it.
EDIT: This is how I'm getting around it until Apple fix it (thank's to #serren for the fix):
First uncheck the Is Initial Controller in your primary window controller (your App won't automatically launch the main window now).
Then:
In the AppDelegate.h:
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate>
// Add strong reference to the root window controller
#property (strong) NSWindowController *rootController;
#end
Finally in AppDelegate.m implement applicationDidFinishLaunching: like so (remember to set your initial controller identifier, here mine is "HomeView"):
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
// Show main window (to avoid powerbox bug)...
NSStoryboard *sb = [NSStoryboard storyboardWithName:#"Main" bundle:nil];
rootController = [sb instantiateControllerWithIdentifier:#"HomeView"];
[rootController showWindow:self];
// Other custom setup for your App...
}
This process will mean that the NSApplication's mainWindow property will be set to the rootController.window automatically. So if you want to get your main window at any time you can still call [[NSApplication sharedApplication] mainWindow]; Also the AppDelegate and the NSApplication singleton both have a strong reference to this window which is important (otherwise the window will be released and the App will crash).
Hope this helps for the time being.
Unfortunately the answer above had nothing to do with my scenario, as there were no ArrayControllers present on the screen creating the NSSavePanel.
One of the comments to the original question pointed me in the right direction though, which was to get rid of the custom WindowController subclass. When I did that, the panel appeared just fine. However, since that's not a great solution (in case you really want to keep your custom class), I kept digging..
FYI, I am using NSStoryboards and building the app for 10.10.
I noticed some weird behavior when I (temporarily) unchecked "Restorable" on my main window--every time the save panel appeared, a new main window of my app appeared. That led me to believe that my app delegate had a major disconnect with the primary window being shown--especially now with storyboards having a separate Application Scene and WindowController.
What I did:
Select my primary window controller and UNCHECK "Is Initial Controller" (i.e. there is no initial controller set for the storyboard)
In my app delegate, in applicationDidFinishLaunching:, I manually created the storyboard and loaded the window controller using instantiateControllerWithIdentifier:
I set the self.window to the created windowController.window property
I made self.window the key and order front (using makeKeyAndOrderFront:)
The app launches, loads the window as before, but now the save panel appears just fine. It also works with a custom windowController subclass.
Finally, as a bonus, I finally have the proper behavior when using applicationShouldTerminateAfterLastWindowClosed (being set to NO)
Short Description:
This look like a bug somehow related to ArrayController and perhaps any other similar controller for that mater or whatever it inherits or the bindings system in IB. Here is a simple code which demonstrates the problem in detail: https://www.dropbox.com/s/atwoc2hweh5fjk6/Bug.zip?dl=0
Long Description:
It looks like that something weird is going on inside the SDK.
In the example that I have provided I have a standard application generated with a standard Xcode 6.1 template. The application is sandboxed. Inside the application delegate we simply test if the NSSavePanel will fire without any problems. The ViewController declares a property called "array" which is later bound to an NSArrayController (see inside Main.storyboard).
If you launch the application in this setup you will see that the NSSavePanel fails. However, if we simply turn off the NSArrayController binding, the call to NSSavePanel miraculously work.
Therefore, it is safe to assume that this is nothing but a bad bug hidden underneath the latest SDK, which apple needs to fix.
Feel free to add the sample to your bug report to Apple.
Woraround:
It looks like if you disable the "Raises For Not Applicable Keys" option inside the array controller binding you get the application to work again without turning off the binding itself. This probably means that an exception is raised before setting up the sandbox connecting to the XPC service therefore making the application misbehave.
The proper fix will be for apple to put the XPC connection initialization code somewhere where it is guarded from weird errors and exceptions therefore ensuring that it is always working.
UPDATE
Based on serenn suggestion I use the following code to make my application behave as expected:
let sb = NSStoryboard(name: "Main", bundle: nil)!
// ---
rootWindowController = sb.instantiateControllerWithIdentifier("MainWindowController") as? NSWindowController
// ---
rootWindowController?.showWindow(self)
In my tests I find that rootWindowController?.showWindow(self) works better to show the window instead of makeKeyAndOrderFront because otherwise the segues don't get properly connected (popups, etc). This method works for me.
According to the App Sandbox Design Guide you should create your own subclass of NSDocument. NSDocument has its own method for presenting the save dialog:
The NSDocument class automatically works with Powerbox. NSDocument also provides support for keeping documents within your sandbox if the user moves them using the Finder.
Remember that the inheritance path of the NSOpenPanel and NSSavePanel classes is different when your app is sandboxed. See Open and Save Dialog Behavior with App Sandbox.
Because of this runtime difference, an NSOpenPanel or NSSavePanel object inherits fewer methods with App Sandbox. If you attempt to send a message to an NSOpenPanel or NSSavePanel object, and that method is defined in the NSPanel, NSWindow, or NSResponder classes, the system raises an exception. The Xcode compiler does not issue a warning or error to alert you to this runtime behavior.
Inside an instance method I'm calling the same selector on the superclass and getting EXC_BAD_ACCESS. I'm using manual reference counting (not ARC), and this is happening in the main thread. Static analysis reports no issues, not that I take that to mean a clean bill of health. The relevant code is as follows:
CommentListMedia.m (stack frame 1 in the trace below):
- (void)play {
if ((comments.isLoading) && (! comments.isLoaded))
playWhenLoaded = YES;
else [super play]; // <-- EXC_BAD_ACCESS happens here
}
MediaControls.m (stack frame 2 in the trace below):
- (void)play {
[media play]; // <-- this calls the code above
[self notifyWithName:MediaControlsDidPlayNotification];
}
MyApp.m (stack frame 11 in the trace below):
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event]; // <-- this calls the code above
...
}
The superclass of CommentListMedia is SequentialMedia, which doesn't figure into the stack trace because the exception occurs before it's reached.
Unfortunately I'm only seeing this in crash reports (from Crashlytics), and haven't been able to reproduce it myself. What strikes me as odd about it is that the reference to the class instance must have been good to perform the play selector in the first place, but somehow by the time it gets to the end, the reference to the superclass is bad. At first I thought the instance might be auto-released or something, but I'm under the impression that autoreleasing happens on the main thread at the end of the run loop, not at some random time in the middle of a call. Any input on what might be causing this or how to debug it would be appreciated.
The call stack on the main thread looks like this:
0 libobjc.A.dylib objc_msgSend + 5
1 MyApp -[CommentListMedia play]
2 MyApp -[MediaControls play]
3 UIKit -[UIApplication sendAction:to:from:forEvent:] + 90
4 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 30
5 UIKit -[UIControl sendAction:to:forEvent:] + 44
6 UIKit -[UIControl _sendActionsForEvents:withEvent:] + 374
7 UIKit -[UIControl touchesEnded:withEvent:] + 590
8 UIKit -[UIWindow _sendTouchesForEvent:] + 528
9 UIKit -[UIWindow sendEvent:] + 832
10 UIKit -[UIApplication sendEvent:] + 196
11 MyApp -[MyApp sendEvent:]
12 UIKit _UIApplicationHandleEventQueue + 7096
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 206
15 CoreFoundation __CFRunLoopRun + 622
16 CoreFoundation CFRunLoopRunSpecific + 522
17 CoreFoundation CFRunLoopRunInMode + 106
18 GraphicsServices GSEventRunModal + 138
19 UIKit UIApplicationMain + 1136
20 MyApp main
0 libobjc.A.dylib objc_msgSend + 5
1 MyApp -[CommentListMedia play]
That may be a crash in -[SequentialMedia play]. Specifically, if that method returns void and makes a call as the last expression in the method, it may be that the [optimizing] compiler generated a tail call. This would effectively cause the method call to disappear from the stack.
Post the contents of the registers from your crash report. $r0 can be quite illuminating (as it is the first arg and should be a viable object).
Also, if there is heavy concurrency in play in your program, then it could be that the object is being released and deallocated by a secondary thread. But, typically, you would see more than one flavor of odd crash (though sometimes not, if your code makes heavy use of synchronization primitives -- it can be remarkable how consistent a concurrent program behaves from run to run).
So some of my users are getting crashes, and I think iv'e tracked it down to the NSWorkspaceDidTerminateApplicationNotification, I can't reproduce the crash at all so I'm not sure where to go?
here is the generated crash log, maybe I'm missing something obvious:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000010
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: invalidate
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff816f211c objc_msgSend + 40
1 com.apple.Foundation 0x00007fff87ef58ea _nsnote_callback + 167
2 com.apple.CoreFoundation 0x00007fff869b3000 __CFXNotificationPost + 1008
3 com.apple.CoreFoundation 0x00007fff8699f578 _CFXNotificationPostNotification + 200
4 com.apple.Foundation 0x00007fff87eec84e -[NSNotificationCenter postNotificationName:object:userInfo:] + 101
5 com.apple.AppKit 0x00007fff878efb58 applicationStatusSubsystemCallback + 593
6 com.apple.LaunchServices 0x00007fff83523e6c LSScheduleNotificationReceiveMessageCallbackFunc(__CFMachPort*, void*, long, void*) + 184
7 com.apple.CoreFoundation 0x00007fff869cf68e __CFMachPortPerform + 366
8 com.apple.CoreFoundation 0x00007fff869a76e1 __CFRunLoopRun + 5201
9 com.apple.CoreFoundation 0x00007fff869a5dbf CFRunLoopRunSpecific + 575
10 com.apple.HIToolbox 0x00007fff80ef07ee RunCurrentEventLoopInMode + 333
11 com.apple.HIToolbox 0x00007fff80ef05f3 ReceiveNextEventCommon + 310
12 com.apple.HIToolbox 0x00007fff80ef04ac BlockUntilNextEventMatchingListInMode + 59
13 com.apple.AppKit 0x00007fff87232e64 _DPSNextEvent + 718
14 com.apple.AppKit 0x00007fff872327a9 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
15 com.apple.AppKit 0x00007fff871f848b -[NSApplication run] + 395
16 com.apple.AppKit 0x00007fff871f11a8 NSApplicationMain + 364
and here is the relevant code:
NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
[center addObserver:self selector:#selector(appTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
- (void)appTerminated:(NSNotification *)note
{
NSString *app = [NSString stringWithFormat:#"%#", [[note userInfo] objectForKey:#"NSApplicationName"]];
if ([app isEqualToString:Somestring])
{
//do something here
}
}
}
If anyone could give me some pointers as to where to look, i'd be eternally grateful, I've been tearing my hair out for days now...
It looks like your window controller is getting deallocated while still being registered with the notification centre. You need to make sure the window controller is unregistered before deallocation. Otherwise, the notification centre will try to post a notification to a deallocated object, which can trigger an EXC_BAD_ACCESS exception.
For instance, in your window controller implementation:
- (void)dealloc {
[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
[super dealloc];
}
This will unregister the window controller with regard to every notification it’s registered with the notification centre.
Looks like a notification fired and tried to call an invalidate method on an object that has been deallocated. Turn on NSZombies and try again.
The following code for initialization of array works ::
NSArray *array = [[NSArray alloc] initWithObjects:#"Toy Story 3",#"Inception",nil];
self.list = [array sortedArrayUsingSelector:#selector(compare:)];
[array release];
[super viewDidLoad];
But the following code doesnt. The iPhone Simulator Terminates as soon as I try to scroll the Table View which i used to view the array. (Only after i scroll onto empty tableViewCells)
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:#"MovieList" ofType:#"plist"];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:plistPath];
NSLog([array objectAtIndex:1]);
self.list = [array sortedArrayUsingSelector:#selector(compare:)];
[array release];
[super viewDidLoad];
This was an example app from the Book "Beginning iPhone Development" by Dave Mark. In the example , they have initialized the array within the code, while i have tried to initialize it from a external file.
The console Log ::
2010-12-22 20:57:43.772 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <RootViewController: 0x9908870>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2010-12-22 20:58:12.480 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <DisclosureButtonController: 0x9b32ab0>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release.
2010-12-22 20:59:13.299 Nav[2474:40b] -[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900
2010-12-22 20:59:13.301 Nav[2474:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900'
*** Call stack at first throw:
(
0 CoreFoundation 0x00db2be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f075c2 objc_exception_throw + 47
2 CoreFoundation 0x00db46fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d24366 ___forwarding___ + 966
4 CoreFoundation 0x00d23f22 _CF_forwarding_prep_0 + 50
5 UIKit 0x0051a9ca -[UITableViewCellLayoutManager layoutSubviewsOfCell:] + 3424
6 UIKit 0x00482e02 -[UITableViewCell layoutSubviews] + 95
7 QuartzCore 0x01c70451 -[CALayer layoutSublayers] + 181
8 QuartzCore 0x01c7017c CALayerLayoutIfNeeded + 220
9 QuartzCore 0x01c6937c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
10 QuartzCore 0x01c690d0 _ZN2CA11Transaction6commitEv + 292
11 QuartzCore 0x01c997d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
12 CoreFoundation 0x00d93fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
13 CoreFoundation 0x00d290e7 __CFRunLoopDoObservers + 295
14 CoreFoundation 0x00cf1bd7 __CFRunLoopRun + 1575
15 CoreFoundation 0x00cf1240 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00cf1161 CFRunLoopRunInMode + 97
17 GraphicsServices 0x016e7268 GSEventRunModal + 217
18 GraphicsServices 0x016e732d GSEventRun + 115
19 UIKit 0x002ca42e UIApplicationMain + 1160
20 Nav 0x00002598 main + 102
21 Nav 0x00002529 start + 53
)
terminate called after throwing an instance of 'NSException'
enter code here
It sounds like this is a perfect job for the debugger, doesn't it? Why not set a breakpoint on the first line and make sure nothing is unexpectedly nil or out of bounds as you step through and inspect your variables? Perhaps paying attention to the error that's undoubtedly logged to the console might be helpful, too?
Given you've mentioned neither the line on which it terminates nor any log messages, this is about as specific as anyone can get.
The first argument to NSLog needs to be an NSString. The object you're passing to it appears to be part of the UIColor cluster. I suggest you change to:
NSLog(#"%#", [array objectAtIndex:1]);
So the first argument is definitely a string and it says just to print a description of whichever object is the next argument.