Question

I have a storyboard app with an embedded table view in a container on the root view controller. The user will make some choices on via popups in the embedded table view. When all the choices are made I want a NEXT button in the view of the root view controller to be activated (un dimmed) so the user can touch it.

I put an action in the RootViewController when I can do this work - check to see if all values are filed in and undid the button if they are, dim it if they are note. But how can I call that action? I have delegates that get fired whenever the user makes a selection, so it seems his is where I would call that action, but it is not available.

Any help would be greatly appreciated.

Bryan

Here is some code:

#import <UIKit/UIKit.h>
//#import "popViewController.h"
#import "pvcProteinIntendedFor.h"
#import "pvcProteinNotOriginateFrom.h"
#import "pvcProteinTaste.h"
#import "pvcProteinPrice.h"
#import "userInputs.h"

@interface embeddedTableViewController : UITableViewController <UITableViewDataSource,UITableViewDelegate,pvcProteinIntendedForDelegate,pvcProteinTasteDelegate,pvcProteinPriceDelegate,pvcProteinNotOriginateFromDelegate>

@property(strong, nonatomic) UIButton *test;

@property(nonatomic, strong) UIButton *parentNextButton;

//Buttons for pop
@property (weak, nonatomic) IBOutlet UIButton *btnProteinIntendedFor;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinNotOriginateFrom;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinTaste;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinPrice;

//Propert for the current PopPover  - this will change to one popover
//@property (strong, nonatomic) popViewController* currentPopoverController;
@property (strong, nonatomic) UIStoryboardPopoverSegue *segPopViewController;

//The button action
//This is to keep track of which button we came from
//@property (weak, nonatomic) IBOutlet UIButton* currentButton;

// Access Protein Intended For
@property (strong, nonatomic) UIStoryboardPopoverSegue *pvcSegueProteinIntendedFor;
@property (strong, nonatomic) pvcProteinIntendedFor *pvcProteinIntendedFor;

// Access Protein Not Orignate From
@property (strong, nonatomic) UIStoryboardPopoverSegue         *pvcSegueProteinNotOriginateFrom;
 @property (strong, nonatomic) pvcProteinNotOriginateFrom *pvcProteinNotOriginateFrom;

// Access Protein Taste
@property (strong, nonatomic) UIStoryboardPopoverSegue *pvcSegueProteinTaste;
@property (strong, nonatomic) pvcProteinTaste *pvcProteinTaste;

// Access Protein Price
@property (strong, nonatomic) UIStoryboardPopoverSegue *pvcSegueProteinPrice;
@property (strong, nonatomic) pvcProteinPrice *pvcProteinPrice;

@end

Here is the implementation file:

#import "embeddedTableViewController.h"
//#import "popViewController.h"
#import "pvcProteinIntendedFor.h"
#import "pvcProteinNotOriginateFrom.h"
#import "pvcProteinTaste.h"
#import "pvcProteinPrice.h"
#import "userInputs.h"
#import "myDataController.h"

@interface embeddedTableViewController ()

//@property(nonatomic, strong) UIButton *parentNextButton;

@end

@implementation embeddedTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


}

- (void)viewDidAppear:(BOOL)animated
{

    //For Testing
    [self.btnProteinIntendedFor setTitle:@"Bakery" forState:UIControlStateNormal];
    [self.btnProteinNotOriginateFrom setTitle:@"China" forState:UIControlStateNormal];
    [self.btnProteinPrice setTitle:@"Extremely Important" forState:UIControlStateNormal];
    [self.btnProteinTaste setTitle:@"Somewhat Important" forState:UIControlStateNormal];
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinIsIntendedFor = @"Bakery";
    dataController.proteinNotOriginate = @"China";
    dataController.proteinHowImportantIsPrice = @"Extremely Important";
    dataController.proteinHowImportantIsTaste = @"Somewhat Important";

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifier] isEqualToString:@"segPopProteinIntendedFor"]) {
        _pvcSegueProteinIntendedFor = (UIStoryboardPopoverSegue *)segue;
        _pvcProteinIntendedFor = [segue destinationViewController];
        [_pvcProteinIntendedFor setDelegate:self];
        }
    else if ([[segue identifier] isEqualToString:@"segPopProteinNotOriginateFrom"]) {
        _pvcSegueProteinNotOriginateFrom = (UIStoryboardPopoverSegue *)segue;
        _pvcProteinNotOriginateFrom = [segue destinationViewController];
        [_pvcProteinNotOriginateFrom setDelegate:self];
    }
    else if ([[segue identifier] isEqualToString:@"segPopProteinTaste"]) {
        _pvcSegueProteinTaste = (UIStoryboardPopoverSegue *)segue;
        _pvcProteinTaste = [segue destinationViewController];
        [_pvcProteinTaste setDelegate:self];
    }
    else if ([[segue identifier] isEqualToString:@"segPopProteinPrice"]) {
        _pvcSegueProteinPrice = (UIStoryboardPopoverSegue *)segue;
        _pvcProteinPrice = [segue destinationViewController];
        [_pvcProteinPrice setDelegate:self];
    }

}

- (void)dismissPopViewController:(NSString *)value{
    [self.btnProteinIntendedFor setTitle:value forState:UIControlStateNormal];
    [[_pvcSegueProteinIntendedFor popoverController] dismissPopoverAnimated: YES];
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinIsIntendedFor= value;
    //[self checkFields];
}

- (void)dismissPopProteinIntendedFor:(NSString *)value{
    [self.btnProteinIntendedFor setTitle:value forState:UIControlStateNormal];
    [[_pvcSegueProteinIntendedFor popoverController] dismissPopoverAnimated: YES];
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinIsIntendedFor= value;
    //[self checkFields];
}

- (void)dismissPopProteinNotOriginateFrom:(NSString *)value {

    [_btnProteinNotOriginateFrom setTitle:value forState:UIControlStateNormal];
    [[_pvcSegueProteinNotOriginateFrom popoverController] dismissPopoverAnimated: YES]; // dismiss the popover
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinNotOriginate = value;
    //[self checkFields];
    }

- (void)dismissPopProteinTaste:(NSString *)value {

    [_btnProteinTaste setTitle:value forState:UIControlStateNormal];
    [[_pvcSegueProteinTaste popoverController] dismissPopoverAnimated: YES]; // dismiss the popover
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinHowImportantIsTaste = value;
    //[self checkFields];
}

- (void)dismissPopProteinPrice:(NSString *)value {

    [_btnProteinPrice setTitle:value forState:UIControlStateNormal];
    [[_pvcSegueProteinPrice popoverController] dismissPopoverAnimated: YES]; // dismiss the popover
    myDataController *dataController = [myDataController sharedDataController];
    dataController.proteinHowImportantIsPrice = value;
    //[self checkFields];
}

-(IBAction)doSomething:(id)sender
{
    self.parentNextButton.enabled = YES;
}


@end

View Controller:

#import <UIKit/UIKit.h>
#import "resultViewController.h"
#import "userInputs.h"
#import "embeddedTableViewController.h"

@interface rootViewController : UIViewController

@property IBOutlet UISwitch *yesNoSwitch;
@property (strong, nonatomic) IBOutlet UIButton *btnNext;
@property (strong, nonatomic) UIStoryboardPopoverSegue *rcvSegueResults;
@property (strong, nonatomic) resultViewController *rvcResults;
@property (strong, nonatomic) userInputs *userInputs;

- (IBAction)unwindResults:(UIStoryboardSegue *)unwindSegue;
- (IBAction)editingChanged:(id)sender;
- (IBAction)switchChanged: sender;

@end

Implementation

#import "rootViewController.h"
#import "myDataController.h"
#import "embeddedTableViewController.h"

@interface rootViewController ()


@end

@implementation rootViewController


-(void)viewWillAppear:(BOOL)animated
{
    //self.eTableViewController.parentNexButton = self.btnNext;
    //[self.eTableViewController parentNextButton] = self.btnNext;

}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //self.eTableViewController = segue.destinationViewController;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Pick a Protein Choices";
}

- (void)viewDidAppear:(BOOL)animated
{

}

- (void)viewDidUnload
{
    [super viewDidUnload];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}



- (BOOL)prefersStatusBarHidden {
    return YES;
}



-(IBAction)switchChanged:(UISwitch *) sender {
    BOOL setting = sender.isOn;
    [self.yesNoSwitch setOn:setting animated:YES];
    myDataController *dataController = [myDataController sharedDataController];
    if (self.yesNoSwitch.isOn) {
        dataController.proteinMustBeOrganic = YES;
    }
    else
    {
    dataController.proteinMustBeOrganic = NO;
    }
}

//Unwind from Results to Inputs
- (IBAction)unwindResults:(UIStoryboardSegue *)unwindSegue
{
}


//Fire this whenever come back from editing; check to see if we should undim button
- (IBAction)editingChanged:(id)sender {

   //*btnNext;

}

@end

OK I still am having an issue. I apologize I am sure it is something stupid.

rootViewController.h

#import <UIKit/UIKit.h>
#import "resultViewController.h"
#import "userInputs.h"
#import "embeddedTableViewController.h"

@interface rootViewController : UIViewController

@property IBOutlet UISwitch *yesNoSwitch;
@property (strong, nonatomic) IBOutlet UIButton *btnNext;
@property (strong, nonatomic) UIStoryboardPopoverSegue *rcvSegueResults;
@property (strong, nonatomic) resultViewController *rvcResults;
@property (strong, nonatomic) userInputs *userInputs;

- (IBAction)unwindResults:(UIStoryboardSegue *)unwindSegue;
- (IBAction)editingChanged:(id)sender;
- (IBAction)switchChanged: sender;

@end

rootViewController.m [just top part]

#import "rootViewController.h"
#import "myDataController.h"
#import "embeddedTableViewController.h"

@interface rootViewController ()

@property(strong, nonatomic) UITableViewController *eTableViewController;

@end

@implementation rootViewController


-(void)viewWillAppear:(BOOL)animated
{

    //self.eTableViewController.parentNexButton = self.btnNext;


}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    self.eTableViewController = segue.destinationViewController;
}

embeddedTableViewController.h [Top]

#import <UIKit/UIKit.h>
#import "pvcProteinIntendedFor.h"
#import "pvcProteinNotOriginateFrom.h"
#import "pvcProteinTaste.h"
#import "pvcProteinPrice.h"
#import "userInputs.h"

@interface embeddedTableViewController : UITableViewController
<UITableViewDataSource,UITableViewDelegate,pvcProteinIntendedForDelegate,pvcProteinTasteDelegate,pvcProteinPriceDelegate,pvcProteinNotOriginateFromDelegate>

@property(nonatomic, strong) UIButton *parentNextButton;

//Buttons for pop
@property (weak, nonatomic) IBOutlet UIButton *btnProteinIntendedFor;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinNotOriginateFrom;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinTaste;
@property (weak, nonatomic) IBOutlet UIButton *btnProteinPrice;

embeddedTableViewController.m

#import "embeddedTableViewController.h"
#import "pvcProteinIntendedFor.h"
#import "pvcProteinNotOriginateFrom.h"
#import "pvcProteinTaste.h"
#import "pvcProteinPrice.h"
#import "userInputs.h"
#import "myDataController.h"

@interface embeddedTableViewController ()

@end

@implementation embeddedTableViewController


-(IBAction)doSomething:(id)sender
{
    self.parentNextButton.enabled = YES;
}

The error I get is on this line of code:

//self.eTableViewController.parentNexButton = self.btnNext;

and the error is

Property 'parentNextButton' not found on object of type 'UITableViewController *'

I think this is telling me that the eTableViewController is not "seeing" the file and thus can't get at that property.

Was it helpful?

Solution

Something like this should work:

#import "ParentViewController.h"
#import "EmbeddedTableViewController.h"

@interface ParentViewController ()

@property(strong, nonatomic) EmbeddedTableViewController *eTableViewController;

@end

@implementation ParentViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.eTableViewController.parentNextButton = self.nextButton;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    self.eTableViewController = segue.destinationViewController;
}

@end



@interface EmbeddedTableViewController : UITableViewController

@property(nonatomic, strong) UIButton *parentNextButton;

@end



#import "EmbeddedTableViewController.h"

@interface EmbeddedTableViewController ()

@end

@implementation EmbeddedTableViewController

-(IBAction)doSomething:(id)sender
{
    self.parentNextButton.enabled = YES;
}

@end

Basically, you capture your EmbeddedTableViewController from the embed segue in the prepareForSegue delegate call in your parent view controller and then in viewDidAppear, you set the parentNextButton in your tableview controller to the parents nextButton. This will take care of the enabling/unenabling of the next button.

As for your "action in the RootViewController", your description of what you are trying to do is a bit unclear to me. I am guessing that the values to be filled in are in the table view. If so, put all your logic in your embedded tableview controller and toggle the enabled state of the next button as needed.

OTHER TIPS

Whenever I encounter this type of problem, I solve it with events.

  1. Post an event from your delegate using NSNotificationCenter
  2. Add a listener in your RootViewController for that event.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top