开发者

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

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

开发者_如何学Go        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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜