Pregunta

Tengo una alertview que muestra bien. En mi cabecera He incluido el UIAlertViewDelegate, pero por alguna razón cada vez que haga clic en un botón en la alerta de mis aplicación se bloquea con un exceso de mal, diciendo que un selector no reconocido fue enviado.

Cualquier idea sería útil. Tengo exactamente el mismo código que se ejecuta en otras clases con ningún problema en absoluto.

Aquí está mi código:

    -(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");
 }
}

Así que lo mejor que puedo con ello, su relación con el hecho de que estoy llamando el método deletePatient de mi UITableViewCell subclase, y que pasa a lo largo del objeto paciente mientras lo hago. Aquí está el código para pasar a lo largo

-(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];
}
¿Fue útil?

Solución

conjunto de objetos patientList como delegado del ejemplo UIAlertView, luego liberado. Cuando el usuario hace clic botón de alerta que llama [alertView delegado: auto clickedButtonAtIndex: buttonIndex], pero el delegado, patientList ya fue liberado y ya no existe. La variable delegado en este momento contiene la basura, por lo que no surprizing que no tienen alertView: clickedButtonAtIndex: Selección;

Sólo la liberación patientList objeto en alertView alerta: clickedButtonAtIndex: método o no la creación de patientList / liberar al crear / soltar clase externa o simplemente utilizar la propiedad:

// en el archivo .h *:

...
PatientListTableViewController *patientList;
...
@property(retain) PatientListTableViewController *patientList;
...

// en el archivo .m *: @synthesize patientList;

...
self.patientList =  [[PatientListTableViewController alloc] init];

Otros consejos

Todo está bien con el código que ya ha proporcionado. A menos que algo enrrollado está sucediendo con el objeto paciente a otro lugar, yo diría que todo se ve bien aquí.

Intente utilizar UIAlerView como objeto autoreleased como esto;

UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:alertString message:nil delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No",nil] autorelease];
[alert1 show];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top