Pergunta

Eu tenho três classes. AlertDetailsVC, UtilizationDetailsVC e SelectIOVC.

UtilizationDetailsVC é, essencialmente, uma cópia do AlertDetailsVC com algumas pequenas modificações.

Quando um utilizador abre o Scene para o meu AlertDetailsVC ele pode pressionar um botão em um Table chamado Applies To.Quando ele a pressiona este Applies To botão, o programa, em seguida, Segues para um novo Scene o que usa SelectIOVC;em seguida, ele define o Delegate de que cena igual a Delegate definido no AlertDetailsVC.

Em seguida, quando o usuário acessa Done no Navigation Bar no SelectIOIOVC Scene;o SelectIOVC classe, em seguida, retorna alguns dados e informações que o usuário selecionado de volta para o AlertDetailsVC.

Este fluxo também é copiado no UtilizationDetailsVC.

Eu adicionei vários NSLog(@"%s",__PRETTY_FUNCTION__); linhas em minha métodos que devem ser chamados.

Agora;quando eu bati Done no meu AlertDetailsVC os métodos são corretamente chamados e o programa de Segues de volta a partir de SelectIOVC para minha AlertDetailsVC e atualiza as informações em que página o usuário digitou.

no entanto, o meu problema é;quando eu faço exatamente a mesma coisa na minha UtilizationDetailsVC página;e sua prima' Done botão;o programa não Segue para trás.

Eu não tenho certeza;os meus registros mostram que a primeira SelectIOVCDidSave é chamado em caso de AlertDetailsVC;mas não é sempre chamado por UtilizationDetailsVC.

Código Relevante:

Utilização:

`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 relevante métodos:

- (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 relevante métodos:

    - (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 relevante métodos:

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

Solução

Eu resolvi esse problema;Eu uso um método chamado - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender em ambos os meus UtilizationDetailsVC assim como o meu AlertDetailsVC.

No entanto;o meu erro foi eu nunca definir o Segue Identifier para o Segue entre UtilizationDetailsVC's Scene e o SelectIOVC Scene.

A definição do valor para o meu segundo Identifier que eu estava verificando fixa o meu problema.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top