我有一个显示正常的警报视图。在我的标题中,我包含了 UIAlertViewDelegate,但由于某种原因,每当我单击警报视图上的一个按钮时,我的应用程序都会因严重过剩而崩溃,说发送了一个无法识别的选择器。
任何想法都会有所帮助。我在其他类中运行完全相同的代码,完全没有问题。
这是我的代码:
-(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");
}
}
所以我能弄清楚的最好的事情,它与我从 UITableViewCell 子类调用 deletePatient 方法并在我这样做时传递患者对象的事实有关。这是传递它的代码
-(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];
}