application crashes on calling popViewController : error: alertView:didDismissWithButtonIndex: - iphone

A description of the problem is as follows:
I have a view, say, view A. To enter certain data, I have an alert,with a text field inside it, which pops up. Once the user enters data into the text field, i have an alertView:didDismissWithButtonIndex: function as follows :
- (void)alertView:(UIAlertView *)alertView:didDismissWithButtonIndex:(NSInteger)buttonIndex {
[ amountEntered resignFirstResponder]; //dismiss keyboard
if (buttonIndex == 1) { //OK clicked, do something
if(lblShowTypedText.text)
data.investmentAmount = lblShowTypedText.text ;
[myTable reloadData];
}
}
Then I have a submit button on my View A, which when clicked pops back to the previous view. Here is where my app crashes. There is no message in the console, however after many runs, I got one message like this:
* -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
2010-06-24 15:33:22.970 BankingAppln[2895:207] CoreAnimation: ignoring exception: * -[NSCFType alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x3c4dce0
Thus i have narrowed down the problem to the alertView:didDismissWithButtonIndex: function. If I do not call the alert, but directly pop back to the previous view, everything is fine.
I must be doing something wrong in my alertView:didDismissWithButtonIndex: function.
Pls help!!

A few things to check:
You set the delegate of the AlertView to the right class (View A)?
Your class (View A) implements the UIAlertViewDelegate protocol.
Probably not, but you never know: You're classname is not equal to a name in apple's private api (don't laugh, happened to me a week ago, costed me 2 hours to figure out)?
EDIT:
Another thing to check:
Your delegate method has the right return type (I think it's "void" in that case)?

Do you really have this method, alertView:didDismissWithButtonIndex:, in your class? and post the code when you call it as well

You need to post where you call the method..but from the error message you gave, the problem is you are calling your method incorrectly.
if it is a method you defined yourself with the implementation above use
[self alertView:myAlertView didDismissWithButtonIndex:myIndex];
also, in your declaration, you have a semicolon after the parameter alertView and you just need a space.

I faced a similar problem and it turns out that with Automatic Reference Counting in place, I needed to keep a reference to the popup around as a property so that it would not be reference collected. That much was fine but I got overzealous and started doing stuff like popup = nil; explicitly and that got me into trouble because some of the delegate methods for the popup were called after I had nil'ed out the reference that I was holding onto and now this popup was not around anymore and the framework crashed due to this little fact.
[__NSCFString alertView:didDismissWithButtonIndex:]: unrecognized selector sent to instance 0x9117c0
So I decided to simply keep allocating a new popup when it was needed and not explicitly nil'ing out the older references. This fixed the issue for me.

Related

controllerview stopAnimating unrecognized selector sent to instance

I am getting this error when I load a new tableview onto my navigational stack.
All of the data displays in the table that I am parsing onto it however once that has finished the app stops working and I get this error.
Just wondering if anyone knows what the problem might be? or how I might be able to debug it?
If you need more code let me know I just don't know what to provide because I'm not sure what the error refers too.
-[VehicleResultViewController stopAnimating]: unrecognized selector sent to instance 0x6a2a680
You need to post more code.
In general, an unrecognized selector error occurs when you try to invoke a method on a class that does not have the method implemented.
Is VehicleResultViewController a UITableViewController/UIViewController? Have you added the stopAnimating method? UIViewController and it's subclass, UITableViewController do not have a stopAnimating method in their default implementation.
If it's a UITableViewController or a UIViewController and you haven't added a stopAnimating method, then you're calling a method that VehicleResultViewController does not have hence the crash.
It's really hard to answer your question more accurately until you:
Post code for where you call the method
Post the header file for VehicleResultViewController so we can see what kind of class is it (or you could just tell us).
It could also be (and more probably is) that you have a UIActivityIndicatorView in your code which you want to stop spinning. In that case, are you sure it's named 'vehicleResultViewController'? Whatever your UIActivityIndicatorView is named, try calling:
[whatever_your_activity_indicator_view_is_named stopAnimating];

Programmatically dismissing a UIAlertView on iOS 5 doesn't call didDismiss delegate method

I'm running into a problem where 9 times out of ten, when I call UIAlertView's dismissWithClickedButtonIndex:animated:, the delegate method alertView:willDismissWithButtonIndex: is not called. Is anyone else running into this problem? I'm about to file a bug with Apple but I'm curious to see if anyone else has run into this issue and figured out any workarounds.
To ensure a consistent behavior across iOS4 and 5, you could just remove the UIAlertView's delegate just prior to calling its dismissWithClickedButtonIndex:animated: method, then manually invoke the delegate method. e.g.
- (void)somethingDidHappen {
id<UIAlertViewDelegate> delegate = myAlertView.delegate;
myAlertView.delegate = nil;
// now, we know the delegate won't be called...
[myAlertView dismissWithClickedButtonIndex:0 animated:NO];
// ...so we call it ourselves below
[delegate alertView:myAlertView clickedButtonAtIndex:0];
}
(That code isn't tested, but you get the point.)
Delegates of UI objects are only called when the user performs an action. Apple assumes that when you do something from code, you already know what you're doing and you don't need to be informed. That applies to all delegates (scrolling delegate methods of UIScrollView vs. code-scrolling, Table View manipulation, ...)
Anyway, what button index should the delegate be called with?.. there is no one when you dismiss programmatically
According to Why doesn't dismissWithClickedButtonIndex ever call clickedButtonAtIndex? the problem is that a different method is being called. However, that doesn't explain why you get erratic calls. On the devices I tested the dismiss method gets called correctly, so I only redirect it to the click version.
Maybe you should file a bug with Apple if you continue seeing the erratic behaviour.
There are alertView:clickedButtonAtIndex:, alertView:didDismissWithButtonIndex: and alertView:willDismissWithButtonIndex:. The method that you're referring to (clickedButtonAtIndex:) is only called when the user explicitly taps on a button on your alert view (hence 'clicked').
Programmatic calls via dismissWithClickedButtonIndex:animated: to dismiss the alert does not seem to call alertView:clickedButtonAtIndex:.
So, if you need some behavior to be always triggered upon the dismissal of the alert view—whether it was triggered by the user tapping on a button or triggered programmatically—then using the didDismissWithButtonIndex: and willDismissWithButtonIndex: makes more sense.

Button Touch Only Works Once

For some reason, interaction with my UIButton only works once. I've tried both via IBAction, and by IBOutlet with "addTarget". I have no idea why.
Context:
BaseViewController
- (IBAction) button_touched:(id)sender; //<-- Declared here, but not implemented
- (void)userInputReceived:(BOOL)bSuccess; //<-- Declared here, but not implemented
ViewController1 : BaseViewController
- (IBAction) button_touched:(id)sender; //<-- Implemented here
- (void)userInputReceived:(BOOL)bSuccess; //<-- Implemented here
Also, this is where I try "addTarget" but that doesn't work either (first touch works, but not the second)
In the "button_touched" method of ViewController1 (vc1), I make a call to another class like this:
[someOtherClassObject doSomethingWithMyView:self];
That class simply pops up a message box, gets user input, then calls back on the viewcontroller:
(Inside SomeOtherClass):
-(void)doSomethingWithMyView:(BaseViewController*)vc
{
// Do Something
[vc userInputReceived:TRUE];
}
Once this workflow has executed once, the button touch never calls the "button_touch" method again. No matter what I do, I can't get this to be called again.
In a thread on one of the popular BBS forums, someone mentioned that a problem like this could be caused by not having the object (vc1) you think you do, but rather, another instance of it. So, I logged the instance like NSLog( "instance: %p", self) in numerous places, and it's always the same.
Any ideas are greatly appreciated. This is very frustrating.
shot in the dark maybe, but its possible that your view controller's view has lost first responder status due to the displaying of the message inside the other object (what type of object is this and how is the message displayed?).
Try after your statement:
[vc userInputReceived:TRUE];
adding the line
[[UIApplication sharedApplication].keyWindow makeFirstResponder:vc.view];

bewildering tableView reloadData crash

For the life of me, I cannot figure this out.
Here's the scenario:
I have a tableview with a searchbar at the top.
I do a search.
I tap a search scope button.
Do another search.
Tap the other search scope button (the one that was selected by default).
Do another search.
Crash
I'm presented with the following:
*** -[CALayer retain]: message sent to deallocated instance 0x4c7fa20
and it points to the following line of code:
[self.tableView reloadData];
I'm not releasing the array I use for the tableview data until the file's dealloc method.
Any ideas? I'm at a loss here. :confused:
Try setting NSZombieEnabled. That should give you a handle on exactly what is being over-released.
Check that all the objects you're using in and around the search are not autoreleased objects - things like [NSDate date] etc. that can get autoreleased.
Maybe post some code showing your search ?

How do I debug an 'unrecognized selector sent to instance' problem?

I have the following code in a view controller that (in all other respects) seems to be working fine:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ProblemViewController *problemViewController = [[ProblemViewController alloc] initWithNibName:#"ProblemViewController" bundle:nil];
problemViewController.problem = (Problem*)[self.problems objectAtIndex:indexPath.row];
[self.navigationController pushViewController:problemViewController];
[problemViewController release];
}
When I run through this function, however, I am getting the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ProblemViewController initWithNibName:bundle:]: unrecognized selector sent to instance 0x57ca80'
I'm at a loss as to what could be causing it, so my question is: How should I best go about debugging this problem? Is there anything obvious I should be checking?
Check the base class for ProblemViewController. I'm betting you're not inheriting from UIViewController, which includes the initWithNibName:bundle: method.
There are a bunch of answers to this question that all basically say the same, correct, thing: Somehow, the method you're trying to call doesn't actually exist.
BUT, if you're beating your head against the wall (like I was for an hour today), make sure you try cleaning your project in xcode first. Sometimes, I don't know why, xcode can get into a bad state and will not properly compile your project into the simulator. It will tell you the build is successful, but when deployed to the simulator, you start seeing runtime errors as though only half your changes were picked up. So yeah, that happens.
You likely don't have that method implemented in your ProblemViewController. Unrecognized selector is, as far as I know, just that there's no method defined in this class's interface that has that signature.
Try declaring it in your interface like this:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;
I thought I better post something on this issue. I fought it for a couple of days. There are a lot of blogs on this, but none of them solved the problem. Some suggested that it had to do with pushViewController needing to specify animated:YES. It worked for some, but that didn't work for the issue I was having. I was using a button to access another view rather than selecting a row from a table view, but was getting the same unrecognized selector error. I was also using a navigation controller so I thought it had something to do with that, but it didn't. Finally, I decided to comment out lines of code till the message went away. After commenting out the method that was causing the problem, the error message still came up in the console. That is when I realized the problem was not with my source code. One site recommended performing a clean and rebuild. I tried all that and still the problem persisted. I then looked at my XIB file using Interface Builder to see what methods(Received Actions) displayed on the File Owner. There was the problem. Not only did the offending method show up once on the File Owner, but it displayed twice. Don't know how to display the image of this here. Anyway, I deleted the methods (Received Actions) with the same name that appeared on the File Owner. I performed a clean and rebuild to see if the error went away and it did. I then uncommented the source I thought was bad and built the project again and the call to the new view was successful.
I will share my experience with the same error code. It is possible to make a mistake my assigning a the object to the wrong target. For example, if you have some UILabel property and you have accidentally assigned the string constant directly to self.myUILabelProperty = #"ups" then you property will become object of type NSString instead of being UILabel, so you loose all the UILabel methods. After that mistake, if you try to use UIlabel methods on the property in code you will get this error message.