I have an alertview that displays perfectly. In my header, I turned on UIAlertViewDelegate, but for some reason every time I click a button in the warning view, my application crashes with a bad excess, stating that an unrecognized selector has been sent.
Any ideas would be helpful. I have the same code that works in other classes without any problems.
Here is my code:
-(void)deletePatient
{
NSLog(@"Delete");
NSMutableArray *visitsArray = [[NSMutableArray alloc] initWithArray:[patient.patientsVisits allObjects]];
int visitsCount = [visitsArray count];
NSLog(@"Visit count is %i", visitsCount);
if (visitsCount !=0)
{
NSString *alertString = [NSString stringWithFormat:@"Would you like to delete %@ data and all their visits and notes?", patient.nameGiven];
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:alertString message:nil delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil];
[alert1 show];
[alert1 release];
}
else if (visitsCount ==0)
{
}
[visitsArray release];
}
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"Yes");
}
else
{
NSLog(@"No");
}
}
So, I can understand this, this is due to the fact that I call the deletePatient method from my UITableViewCell subclass and pass the patient object when I do this. Here is the code for passing it along
-(IBAction)deletePatient:(id)sender
{
NSLog(@"Delete Patient:%@",patient.nameGiven);
PatientListTableViewController *patientList = [[PatientListTableViewController alloc] init];
patientList.patient = patient;
UITableView *tableView = (UITableView *)[self superview];
tableView.scrollEnabled = YES;
[patientList deletePatient];
menuView.center = CGPointMake(160,menuView.center.y);
[patientList release];
}