Crash when using gesture recognizers in StoryBoard - iphone

UPDATE
This is an old question for an old version of Xcode. It turned out that the issue was a bug in Xcode which has been fixed.
Original
I have a storyboard generated from making a new tab iphone application (with ARC)
In one of my tabs, if I drag a gesture recognizer (any, but let's say Pan) onto a control, and then set the selector to an action, it just crashes as soon as I go to the tab.
There is nothing in the Console -- it appears to be happening while the storyboard is being loaded (viewDidLoad is never called).
I can't figure out how to get more information
On a different tab, this works fine. Both tabs were generated automatically.
(it's possible I messed something up in the view, but I don't have a clue to figuring out what I did).
If I make gestures programmatically, they work fine, but it's nice to have it work in the storyboard, and I'm afraid that whatever is wrong will cause a crash some other way at some point.
MORE INFO
In the simulator I get
-[__NSCFString setView:]: unrecognized selector sent to instance 0x6d2db70
Again, need debugging techniques -- for example, is there a way to find out what object 0x6d2db70 is?
Which is exactly like this question (with no answer):
Gesture recognizer in Interface builder crashes my app
MORE INFO
This is trivial to reproduce
New iPhone tabbed application, ARC and Storyboard on
Drag tap gesture onto second tab's view (works on first one)
Create an (IBAction)
Connect the gesture's selector connection to the action from #3
run, go to second tab
Crashes. Same thing with my app, default tab works, other tabs don't

The error message tells us that the program is sending the setView: message to an instance of __NSCFString (which is obviously the private implementation class of NSString).
Make sure you have tried running with zombies enabled. A zombie can easily cause an unrecognized selector error.
If it's not a zombie, put a breakpoint on -[NSObject doesNotRecognizeSelector:]. When the breakpoint is hit, you may be able to figure out the problem just from the stack trace. If not, you can print the debugDescription of the object (which is the same as the description for most classes).
On the simulator, you can ask the debugger to print the object's debugDescription like this:
(gdb) frame 0
#0 0x013bcbff in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po ((int*)$ebp)[2]
this is my test string
On the device, you do this:
(gdb) frame 0
#0 0x344bca22 in -[NSObject doesNotRecognizeSelector:] ()
(gdb) po $r0
this is my test string
Update
Based on your steps to reproduce, this is a bug in UIKit. File a bug report. You can work around the bug by creating a strong outlet on SecondViewController and connecting it to the gesture recognizer. Make sure you set the outlet to nil in viewDidUnload.
Update
Do not ever set your outlet to nil -- part of the bug is that UIKit isn't retaining -- you need to keep your reference to make sure that the recognizers aren't released.

In my case, when auto-creating the IBOutlet for the gesture recognizer by drag-n-dropping in the code, Xcode correctly created the property with a "strong" attribute, but it also added the "set to nil" in viewDidUnload. Removing the "set to nil" solved the issue for me.

Related

xib overlay in storyboard causing uncaught exception

My main app is using Storyboard's for laying all my views out. Next... I've also got a xib file that holds a few buttons that I'd like to apply in a fancy sort of overlay. This is also working great using a technique I found here: http://www.stackoverflow.com/a/12574190/949538
The Files Owner is hooked up to the main view controller. And from a button on my main view, I can pop open this xib nicely.
The problem comes from trying to attach an IBAction to anything I put on this xib. All of i have no warnings, no build errors, everything looks fine. Until I pop open the xib/view, and hit one of my buttons, then I get this:
2012-11-19 15:44:48.685 Frolfer[89367:c07] -[UIViewController closeStartPanel:]: unrecognized selector sent to instance 0x8352e90
2012-11-19 15:44:48.686 Frolfer[89367:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController closeStartPanel:]: unrecognized selector sent to instance 0x8352e90'
MainViewController.m
-(IBAction)closeStartPanel:(id)sender {
NSLog(#"close start panel");
}
It's got to be something just so basic that I'm forgetting / missing.
Any thoughts?
P.S.
There literally is not much code written yet, but if you'd like to see anything more just let me know. I'm not sure exactly what it is that you'd like to see...
Thanks in advance!!
- drew
Is there closeStartPanel: selector defined for that UIButton ? Can you post code for that? the exception clearly states that it is not able to find closeStartPanel selector for that UIButton in UIViewController...
I figured it out!
Not sure why I didn't try this before, but it works great now.
Usually when I'm in the Storyboard, I'd drag 'Touch Up Inside' handle over on top of my button to see the available IBActions's that I had created in my header. With the xib file, this wasn't happening at all. So as noted previously, I changed class of the Files Owner on my xib to my MainViewController.
After that, all my defined IBActions were appearing as I had expected them to when dragging 'Touch Up Inside' over to the button on screen in IB.
That's where the crashes started happening though.
This morning, I removed all associations to MainViewController on my xib file, and by accident, had drug the 'Touch Up Inside' handle over to First Responder. I guess I don't play with First Responder much... but to my surprise, all my IBActions were listed in there. For some reason, I thought I wouldn't see them.
After a clean and compile... boom, they worked! I guess the only downside (if you want to call it that), is that in the code view, it doesn't give an indication that your defined IBAction is hooked up to a button in the IB with the filled in gray dot like my other buttons that are directly on the storyboard do.
Oh well, seems to be working the way I had hoped (for now), so I'm going to just roll with it.
:-)
Have a great Thanksgiving weekend.
- Drew

Xcode application running on Iphone but crashing on Ipad

I made a universal application that contains NIB files for both ipad and iphone UI's. In my view controllers initWithNibName method I call UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM() to detect whether the controller is running on iphone or ipad.
I then launch their respective nib files. When I run the app on iphone, it works fine, but when I run it on ipad it eventually crashes with a EXC_BAD_ACCESS error. This error occurs when I use a view controller to launch another view controller, which then launches another one in the navigation stack. This error occurs as soon as I click the view that belongs to the third controller of the stack.
I cannot distinguish a difference between the NIB files that would cause a crash. I have been working tirelessly to figure out why this is happening but I cannot fix this error. Does anyone have any insight into what might be going on?
Any advice on how to approach fixing this problem would be very appreciated.
The first thing you should do is enable the "All Exceptions" break point. This will often accurately tell you the line of code where the EXC_BAD_ACCESS is happening.
Next, I would turn on zombies and see where the over-release is happening. To do so, in Xcode, while holding the option key, click Product | Run.... In the ensuing window, add NSZombieEnabled to the environment variables list.
Then run. Do the normal things you do to cause the crash and see where the debugger lands. With any luck, it will stop where the problem is actually occurring.
When you get a EXC_BAD_ACCESS it means you're trying to access/release something that's already been released. If you're in a non-ARC situation, it normally means you've inadvertently released something when you didn't mean to, so just check for alloc/init and release balance. If, however, you're in an ARC situation, I would bet it has to do with not niling a delegate when a view controller gets released.
For example, if you have a MKMapView and have set its delegate to your view controller, you should nil its delegate when your view gets unloaded or dealloc'd. Otherwise, messages will continue to get set to it. Or, another possibility is that you've added your view controller as an NSNotificationCenter observer and didn't remove it as an observer when the view controller was unloaded or dealloc'd.
Another possibility is that you're re-using view controllers between the two versions of your universal app. If you are accessing anything by an identifier that doesn't exist in the nib for the iPad, that would cause a crash--though if you're using nibs as opposed to storyboards, that may not be an issue.
That's about all I can think of for now. Try to zero in on where it's happening and post code here if you still can't figure it out.
Best regards.

app crashes without any log messages

In my App I have an UIViewController, that pushed by another ViewController's navigation controller. It contains some views, buttons, scrollViews and accelerometer support. When I tapping "back" button of navigationController, app crashes without any log message, except this one:
"warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.3 (8J2)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).
(gdb)"
debugger links me to this line in main.m:
int retVal = UIApplicationMain(argc, argv, nil, nil);
with "EXEC_BAD_ACCESS"
what does this mean?
EDIT:
all of you are right.
problem was in accelerometer. I setted delegate ([UIAccelerometer sharedAccelerometer].delegate = self;) and didn't remove it. that's why there was no line in my code for debugger to link to. I just added this:
- (void)viewWillDisappear:(BOOL)animated {
[UIAccelerometer sharedAccelerometer].delegate = nil;
}
and problem gone. So, If you are using any device functions, be careful with delegates.
Did you set Zombies to enabled? That will enable you to track if you access an already released object, and that tells you which object it is.
If you are using XCode 4, you can enable zombies in Project -> Edit Scheme -> Diagnostics by checking the "Enable Zombies" checkbox.
Also make sure you have "Break on Exception" set on - in XCode 4 go to the Breakpoint View, press the Plus sign in the lower left corner, and choose "Add Exception Breakpoint ..." for all exceptions. Then XCode will break at the point where the exception occurs, and you will see more than just UIApplicationMain as the location.
This means you have tried to read/write a block of memory you have no permission to. Maybe you're trying to use an object you haven't allocated/initialized. Check your code, debug it and inspect variables to find a solution.
I guess you had a memory warning and you app deallocated some datas tha are not there anymore when you go back.
Put some breakpoint into didReceiveMemoryWarning, dealloc, viewDidUnload and viewDidLoad to see what happens in your previous controller.
EXC_ BAD_ ACCESS is an exception (EXCeption_ BAD_ ACCESS).
If you set a breakpoint on objc_exception_throw (sign + on the lower left corner of debug tab), you'll get those.
You might want to look at NSZombieEnabled (http://www.cocoadev.com/index.pl?NSZombieEnabled), as you're probably trying to access a dealloc'd object.

Weird XIB file issue

Experiencing a weird problem in a modified program written by me. In my first iteration, the view controller had an IBAction by the title userSpecifyingInput and had all my buttons wired up to this IBAction.
To make the design more sophisticated, I introduced userSpecifyingDigit and userSpecifyingLetter and accordingly had some buttons wiring up to the first IBAction (userSpecifyingDigit) and the next button wiring up to the second IBAction (userSpecifyingLetter).
Upon running my program, it gave me this error:
terminating app: NSInvalidArgumentException
Unrecognized selector sent to instance
And these selectors were alternating between userSpecifyingInput and userSpecifyingDigit which did not make sense as userSpecifyingInput was completely removed from my ViewControllers interface and implementations.
Now I am not sure why userSpecifyingInput still existed, but after dabbling with sent events, I noticed that the buttons were wired upto the new selectors as well as the old selector.
I had to manually remove the old selector from the touchupinside events for all the buttons.
Naturally this does not seem to be a very convenient way to go about proceedings and if the view controller selectors are modified then the touch events ought to be automatically removed.
Am I missing something here? This is a pretty open ended question with different answers
Eliminating an IBAction from your implementation will not remove any previous links to it in IB. I haven't heard of any XCode/IB preferences to shortcut this issue.
Sounds like the xib still thinks one of it's objects is hooked up to the UIViewController, but the function on the UIViewController is no longer there. To check and fix this...
Click on the xib file in the project navigator
Select the File's Owner
Click on the Connections Inspector
Verify that none of these connections are invalid
I would also look in the UIViewController to make sure no automagically created references exist here as well.

Works in iPhone Simulator, but not on Phone

So I have an app which runs fine on the simulator, but not on the actual device.
At runtime, it gives me the following error:
2010-12-05 19:58:32.006 Sports[4668:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView isEqualToString:]: unrecognized selector sent to instance 0x800800'
A bit about the structure: I have a Tab Bar Controller, the first view being a UINavigationController.
The view in there is a UITableView. One thing that may or may not be related is that if I do #synthesize tableView; in the table view controller, the table stays blank on both simulator and phone (but does not crash).
If I take that out, it loads the correct data on the simulator, and crashes on the phone.
Where should delegate/dataSource be linked to in the Interface Builder? I tried linking it to "View" to "File's Owner", and making a new "ViewController" and none of those worked.
Both the delegate and dataSource should be linked to File's Owner, which is the view controller class that declares the table view as an IBOutlet; this should be the same view controller that owns the nib file. Additionally, that view controller should be implement the UITableViewDelegate and UITableViewDataSource protocols.
Add that #synthesize line back in, (unless you're subclassing UITableViewController, as pointed out by grahamparks in the comments!) make sure those connections are right, and, finally, make sure you've declared an IBOutlet for the table view, and connected that properly between your class and interface builder.
Found it!
Turns out that there wasn't really a problem with this at all. The problem was that the date field in my database, when run on my phone was always zero/nil.
Why? Because the NSDate object created never initialized and stayed at nil.
Why?
Because my phone is in 24 hour time and did not parse the am and pm properly.
Lessons learned!
Run your app with NSZombieEnabled set to yes. See http://www.cocoadev.com/index.pl?NSZombieEnabled for an explanation about it and how to set it. I think what you will find is that the app will now throw an exception in the simulator telling you that you are sending a message to an object that has been released.
Based on the error message you are receiving, I expect the culprit is a NSString or NSMutableString object. If it is an NSString then warning, that NSString could be shared by several different objects so figuring out where the extra release is might be hard.
Never fear though, Instruments helps tremendously in this regard. Here is a link that explains how to use Instruments to find out exactly where your object is being retained and released so you can track down which release is inappropriate. http://www.markj.net/iphone-memory-debug-nszombie/
Good luck!