我有一個alertview顯示罰款。 在我的頭文件中,我已經包含了UIAlertViewDelegate,但由於某種原因,每當我單擊警報視圖上的按鈕時,我的應用程序崩潰時會出現一個不合理的過量,並說發送了無法識別的選擇器。UIAlertView按鈕導致崩潰,當所有其他工作正常
任何想法都會有所幫助。我有完全相同的代碼在其他類中運行,完全沒有問題。
這裏是我的代碼:
-(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];
}
什麼是無法識別的選擇器簽名? – executor21 2010-03-04 03:26:53
我在控制檯得到的錯誤是這樣的: - [NSCFType alertView:clickedButtonAtIndex:]:無法識別的選擇器發送到實例0x1766400' – monotreme 2010-03-04 05:21:20