Question

I have three classes. AlertDetailsVC, UtilizationDetailsVC and SelectIOVC.

UtilizationDetailsVC is essentially a copy of AlertDetailsVC with some small modifications.

When a user opens up the Scene for my AlertDetailsVC he can press a button in a Table called Applies To. When he presses this Applies To button, the program then Segues to a new Scene which uses SelectIOVC; it then sets the Delegate of that scene equal to the Delegate defined in the AlertDetailsVC.

Then when the user hits Done on the Navigation Bar on the SelectIOIOVC Scene; the SelectIOVC class then returns some data and information that the user selected back to the AlertDetailsVC.

This flow is similarly copied in the UtilizationDetailsVC.

I added several NSLog(@"%s",__PRETTY_FUNCTION__); lines in my methods that should be being called.

Now; when I hit Done in my AlertDetailsVC the methods are correctly called and the program Segues back from SelectIOVC to my AlertDetailsVC and updates the information on that page the user entered.

however my problem is; when I do the exact same thing in my UtilizationDetailsVC page; and press its' Done button; the program does not Segue back.

I am not sure; my logs show that the first SelectIOVCDidSave is called in the case of AlertDetailsVC; but it is not ever called by UtilizationDetailsVC.

Relevant Code:

Utilization:

`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 relevant methods:

- (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];
}

Alerts:

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 relevant methods:

    - (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 relevant methods:

- (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];
}
Was it helpful?

Solution

I solved this problem; I use a method called - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender in both my UtilizationDetailsVC as well as my AlertDetailsVC.

However; my mistake was I never set the Segue Identifier for the Segue between UtilizationDetailsVC's Scene and the SelectIOVC Scene.

Setting the value to my according Identifier that I was checking for fixed my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top