El delegado de la llamada al método de una clase, pero no de otra clase con idéntica estructura
-
20-12-2019 - |
Pregunta
Tengo tres clases. AlertDetailsVC
, UtilizationDetailsVC
y SelectIOVC
.
UtilizationDetailsVC
es esencialmente una copia de AlertDetailsVC
con algunas pequeñas modificaciones.
Cuando un usuario abre la Scene
para mi AlertDetailsVC
él puede presionar un botón en un Table
llama Applies To
.Cuando se pulsa este Applies To
botón, a continuación, el programa Segues
a una nueva Scene
que utiliza SelectIOVC
;a continuación, establece el Delegate
de esa escena igual a la Delegate
se define en el AlertDetailsVC
.
A continuación, cuando el usuario llega a Done
en el Navigation Bar
en el SelectIOIOVC
Scene
;el SelectIOVC
la clase, a continuación, devuelve los datos y la información que el usuario ha seleccionado la espalda a la AlertDetailsVC
.
Este flujo es similar copiado en el UtilizationDetailsVC
.
He añadido varios NSLog(@"%s",__PRETTY_FUNCTION__);
líneas en mis métodos que debe ser llamado.
Ahora;cuando llegué a la Done
en mi AlertDetailsVC
los métodos son correctamente llamado, y el programa de Segues
de vuelta de SelectIOVC
a mi AlertDetailsVC
y actualizaciones de la información de la página que el usuario ingresa.
sin embargo, mi problema es;cuando yo hago exactamente lo mismo en mi UtilizationDetailsVC
la página;y la prensa de su' Done
botón;el programa no Segue
de la espalda.
No estoy seguro;mis registros muestran que la primera SelectIOVCDidSave
se llama en el caso de AlertDetailsVC
;pero no es llamado por UtilizationDetailsVC
.
Código Correspondiente:
Utilización:
`UtilizationDetailsVC.h`:
@class UtilizationDetailVC;
@protocol UtilizationDetailsVCDelegate <NSObject>
- (void)utilizationDetailsVCDidCancel: (UtilizationDetailVC *)controller;
- (void)utilizationDetailsVCDidDelete: (UtilizationDetailVC *)controller;
- (void)utilizationDetailsVCDidSave: (UtilizationDetailVC *)controller;
@end
@interface UtilizationDetailVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, SelectTimeVCDelegate, SelectDaysVCDelegate, SelectIOVCDelegate, SelectIODetailsVCDelegate, SelectTimeLengthVCDelegate, MessageVCDelegate, UtilizationContactsVCDelegate, SelectDateVCDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (strong, nonatomic) NCUtilization *utilization;
@property (weak, nonatomic) id <UtilizationDetailsVCDelegate> delegate;
@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSIndexPath *indexPath;
@property (strong, nonatomic) IBOutlet UITableViewCell *cellEnabled;
@property (strong, nonatomic) IBOutlet UITextField *titleField;
@property (strong, nonatomic) IBOutlet UITextField *descriptionField;
@property (strong, nonatomic) IBOutlet UILabel *startTimeField;
@property (strong, nonatomic) IBOutlet UILabel *endTimeField;
@property (strong, nonatomic) IBOutlet UISwitch *allDayField;
@property (strong, nonatomic) IBOutlet UILabel *daysField;
@property (strong, nonatomic) NSArray *days;
@property (strong, nonatomic) IBOutlet UILabel *appliesToField;
@property (strong, nonatomic) IBOutlet UILabel *notifyWhenField;
@property (strong, nonatomic) IBOutlet UILabel *changeExistsForField;
@property (strong, nonatomic) IBOutlet UILabel *contactsField;
@property (strong, nonatomic) NSArray *contactUUIDs;
@property (strong, nonatomic) IBOutlet UILabel *messageField;
@property (strong, nonatomic) IBOutlet UILabel *startDateField;
@property (strong, nonatomic) NSDate *startDate;
@property (strong, nonatomic) IBOutlet UILabel *endDateField;
@property (strong, nonatomic) NSDate *endDate;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
UtilizationDetailsVC.m métodos relevantes:
- (void)selectIOVCDidCancel:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)selectIOVCDidSave:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
// Update input/output information with user selection on UI.
self.appliesToField.text = controller.ioDescription;
self.notifyWhenField.text = @"";
[self.navigationController popViewControllerAnimated:YES];
}
Alertas:
AlertDetailsVC.h:
#import <UIKit/UIKit.h>
#import "NCAlert.h"
#import "SelectTimeVC.h"
#import "SelectDaysVC.h"
#import "SelectIOVC.h"
#import "SelectIODetailsVC.h"
#import "SelectTimeLengthVC.h"
#import "MessageVC.h"
#import "AlertContactsVC.h"
@class AlertDetailsVC;
@protocol AlertDetailsVCDelegate <NSObject>
- (void)alertDetailsVCDidCancel: (AlertDetailsVC *)controller;
- (void)alertDetailsVCDidDelete: (AlertDetailsVC *)controller;
- (void)alertDetailsVCDidSave: (AlertDetailsVC *)controller;
@end
@interface AlertDetailsVC : UITableViewController <UITextFieldDelegate, UIActionSheetDelegate, SelectTimeVCDelegate, SelectDaysVCDelegate, SelectIOVCDelegate, SelectIODetailsVCDelegate, SelectTimeLengthVCDelegate, MessageVCDelegate, AlertContactsVCDelegate>
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (strong, nonatomic) NCAlert *alert;
@property (weak, nonatomic) id <AlertDetailsVCDelegate> delegate;
@property (strong, nonatomic) NSString *identifier;
@property (strong, nonatomic) NSIndexPath *indexPath;
@property (strong, nonatomic) IBOutlet UITableViewCell *cellEnabled;
@property (strong, nonatomic) IBOutlet UITextField *titleField;
@property (strong, nonatomic) IBOutlet UITextField *descriptionField;
@property (strong, nonatomic) IBOutlet UILabel *startTimeField;
@property (strong, nonatomic) IBOutlet UILabel *endTimeField;
@property (strong, nonatomic) IBOutlet UISwitch *allDayField;
@property (strong, nonatomic) IBOutlet UILabel *daysField;
@property (strong, nonatomic) NSArray *days;
@property (strong, nonatomic) IBOutlet UILabel *appliesToField;
@property (strong, nonatomic) IBOutlet UILabel *notifyWhenField;
@property (strong, nonatomic) IBOutlet UILabel *changeExistsForField;
@property (strong, nonatomic) IBOutlet UISwitch *localAlertField;
@property (strong, nonatomic) IBOutlet UISwitch *localAlertAudioField;
@property (strong, nonatomic) IBOutlet UILabel *contactsField;
@property (strong, nonatomic) NSArray *contactUUIDs;
@property (strong, nonatomic) IBOutlet UILabel *messageField;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
AlertDetailsVC.m métodos relevantes:
- (void)selectIOVCDidCancel:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)selectIOVCDidSave:(SelectIOVC *)controller
{
NSLog(@"%s",__PRETTY_FUNCTION__);
// Update input/output information with user selection on UI.
self.appliesToField.text = controller.ioDescription;
self.notifyWhenField.text = @"";
[self.navigationController popViewControllerAnimated:YES];
}
SelectIOVC:
SelectIOVC.h
#import <UIKit/UIKit.h>
@class SelectIOVC;
@protocol SelectIOVCDelegate <NSObject>
- (void)selectIOVCDidCancel: (SelectIOVC *)controller;
- (void)selectIOVCDidSave: (SelectIOVC *)controller;
@end
@interface SelectIOVC : UITableViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
NSArray *selectIOType;
NSArray *selectIO;
}
@property (weak, nonatomic) IBOutlet UIBarButtonItem *doneButton;
@property (weak, nonatomic) id <SelectIOVCDelegate> delegate;
@property (weak, nonatomic) NSString *identifier;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@property (assign, nonatomic) NSUInteger type;
@property (assign, nonatomic) NSUInteger io;
@property (assign, nonatomic) NSUInteger number;
@property (strong, nonatomic) NSString *ioDescription;
- (IBAction)cancel:(id)sender;
- (IBAction)done:(id)sender;
@end
SelectIOVC.m métodos relevantes:
- (IBAction)cancel:(id)sender
{
[self.delegate selectIOVCDidCancel:self];
NSLog(@"%s",__PRETTY_FUNCTION__);
}
- (IBAction)done:(id)sender
{
NSLog(@"%s",__PRETTY_FUNCTION__);
NSString *typeDescription = [selectIOType objectAtIndex:self.type];
NSString *ioDescription = [selectIO objectAtIndex:self.io];
self.ioDescription = [NSString stringWithFormat:@"%@ %@ %01d", typeDescription, ioDescription, self.number];
[self.delegate selectIOVCDidSave:self];
}
- (void)viewDidUnload {
[self setDoneButton:nil];
[super viewDidUnload];
}
Solución
He resuelto este problema;Yo uso un método llamado - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
en mi UtilizationDetailsVC
así como a mi AlertDetailsVC
.
Sin embargo;mi error fue nunca el Segue Identifier
para el Segue
entre UtilizationDetailsVC
's Scene
y el SelectIOVC
Scene
.
Ajuste el valor a mi de acuerdo Identifier
que yo estaba mirando por solucionado mi problema.