In my iPhone app, I have a NSObject
A class and a UIViewController
B class. I want to call a instance method in B class from A. I used the following code.
Bclass *vc = [[Bclass alloc]init];
[vc hideAlert:NSString];
[vc release];
and in B class:
- (void)hideAlert:(NSString*)message{
UIAlertView *shareAlrt = [[UIAlertView alloc] initWithTitle:@""
message:message
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[shareAlrt show];
[shareAlrt release];
}
and the method called and show a AlertView. When click on the Ok button, I want to navigate to class Cclass.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
Cclass *vc = [[Cclass alloc]initWithNibName:@"Cclass" bundle:[NSBundle mainBundle]];
[self presentModalViewController:vc animated:NO];
[vc release];
}
}
But when I click on the Ok button, the app crashes. Whats happening here? I have added <UIAlertViewDelegate>
in the B class.h file, but still the same error. Please help
I am getting the error code *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType alertView:clickedButtonAtIndex:]: unrecognized selector sent to instance 0x81baa80'
This has been answered by presuming that u have no other button except cancel button titled as "OK". Assumption is made by seeing your displayed code.
You have used Cancel button on which u cant handle delegate to perform any action.
If you look at the documentation of UIAlertViewDelegate class reference
Just change the method