xib overlay in storyboard causing uncaught exception - iphone

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

Related

Crash when using gesture recognizers in StoryBoard

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.

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.

UISegmentedControl Problem setting hidden

Hi I regulary created using IB one UISegmentedControl that I called showAllSwitch.
If I try to do [showAllSwitch setHidden:YES]; nothing happens!
Why? How can I do to hide it?
Where are you calling setHidden? if it is being called before it is added to the view, then there could be problems. Try calling it in viewDidAppear and see it that works. If it doesn't either the segmentedControl is not connected correctly in IB, or there is a rather big problem that we are missing.
Hiding an object is relatively straight forward. So if there is a problem then its something simple. You need to just go through some basic diagnostic steps:
Verify that your segmented control is actually connected to the correct outlet in IB. Really. Go look. Even if you are sure. Go look again.
Verify that the line where you are hiding it is being called. Add an NSLog just after and see if it shows up when it should.
Make sure that the hide command is not getting sent too soon. If its being sent in ViewDidLoad try setting it up in ViewDidAppear.

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!

Why would a UIDatePicker with no functionality, added to my app via IB, cause my app to crash?

I just added a UIDatePicker to my iPad app using IB, linked it to its outlet in the code, saved it in IB, added the UIPickerViewDelegate to my UIViewController in the code, as well as added the UIDatePicker outlet in code. When I build and run, the app launches, but will crash intermittently when I attempt to open the popover view that contains the datepicker. I say intermittently because the popover view will occasionally open successfully, but never more than once (it always crashes the second time you open the popover, if it doesn't crash the first time). Also, in the console, I get the following messsage
objc[594]: FREED(id): message lastClickRow sent to freed object=0x6015a70
Why is this happening and how can I fix it?
What does that console message indicate?
It may be worth mentioning that the popover view also contains a table view along with the datepicker control.
Thanks so much in advance for your help!
I too had a tough time getting through this problem but at last got it resolved.
Instead of adding UIDatePicker in interface builder, add it dynamically or programatically. It surely worked for me and hope that it works for you too.
UIDatePicker *_datePicker=[[UIDatePicker alloc] initWithFrame:frame];
[self.view addSubview:_datePicker];
This is almost certainly a reference count issue. It seems odd that your view controller (which I'm assuming is the delegate of your UIDatePicker, since that's where you implemented the protocol) would be released during normal operations, but that's the first thing you should look at - that the delegate is set and remains a valid object at the time you display the popup view.
One funny thing you could have done is to release it UIPopOverController reference after passing it the [presentPopover...] message, just like we do at passing a presentModalViewController message to the UIViewController.
I faced this problem too, one thing you can do is something like
self.funnyPopoverController = aPopoverController;
(of course funnyPopoverController is retain type property here).
Otherwise its hard to predict whats happening without staring at the code for some long long time_t hours :)