I have an alertview which displays fine. In my header I've included the UIAlertViewDelegate, but for some reason whenever I click a button on the alert view my app crashes with a bad excess, saying that an unrecognized selector was sent.
Any ideas would be helpful. I have the exact same code running in other classes with no problem at all.
Here's my code:
-(void)deletePatient
{
NSLog(@"Delete");
//Patient *patientInRow = (Patient *)[[self fetchedResultsController] objectAtIndexPath:cellAtIndexPath];
NSMutableArray *visitsArray = [[NSMutableArray alloc] initWithArray:[patient.patientsVisits allObjects]];
//cellAtIndexPath = indexPath;
int visitsCount = [visitsArray count];
NSLog(@"Visit count is %i", visitsCount);
if (visitsCount !=0)
{
//Display AlertView
NSString *alertString = [NSString stringWithFormat:@"Would you like to delete %@'s 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)
{
//Do something else
}
[visitsArray release];
}
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(@"Yes");
}
else
{
NSLog(@"No");
}
}
So the best I can figure it out, its related to the fact I'm calling the deletePatient method from my UITableViewCell subClass, and passing along the patient object as I do so. Here's 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];
}