views:

213

answers:

3

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: 

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

vodkhang
yes, the function is in my class.. also I never make a call to the method, does it not get invoked when appropriate buttons are clicked in the alert? sorry If I'm wrong, but im new to Iphone development. What I basically want to do, is when data is entered into the text field in the alert, and OK is clicked, I want to store this data, and display it in the view..
elnino_9
Once the user enters data into the text field, i have an alertView:didDismissWithButtonIndex: function as follows : (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {These lines make me confused, your function is not alertView:didDismissWithButtonIndex:, it is alertView:clickedButtonAtIndex. Can you really post the function alertView:didDismissWithButtonIndex ? The function is called because your class is the UIAlertView Delegate
vodkhang
sorry for the mistake, I was messing around with both the methods. My method is didDismissWithButtonIndex only. I have included the UIAlertView Delegate in my class.As Eiko pointed out, i removed the call to viewWillAppear and my function looks as above.
elnino_9
Can you post the UIAlertView init code. Did you set the delegate to self? Can you try to copy the method name to the interface
vodkhang
A: 

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)?
dalind
I checked all that you said, all of them are OK.
elnino_9
Than I think we need some more code.
dalind
A: 

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.

Jesse Naugher