0

我在根视图控制器的容器中有一个带有嵌入式表格视图的故事板应用程序。用户将通过嵌入式表格视图中的弹出窗口做出一些选择。做出所有选择后,我希望激活根视图控制器视图中的 NEXT 按钮(未变暗),以便用户可以触摸它。

当我可以完成这项工作时,我在 RootViewController 中放置了一个操作 - 检查是否所有值都已归档,如果有则取消按钮,如果有注释,则将其调暗。但我怎么能称这个动作呢?每当用户进行选择时,我都有被解雇的代表,所以看起来他就是我要调用该操作的地方,但它不可用。

任何帮助将不胜感激。

布莱恩

这是一些代码:

#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

这是实现文件:

#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

视图控制器:

#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

执行

#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

好的,我仍然有问题。我很抱歉,我确信这是愚蠢的。

根视图控制器.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 [只是顶部]

#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 [顶部]

#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;

嵌入式TableViewController.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;
}

我得到的错误是在这行代码上:

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

错误是

在“UITableViewController *”类型的对象上找不到属性“parentNextButton”

我认为这告诉我 eTableViewController 没有“看到”文件,因此无法获取该属性。

4

2 回答 2

1

像这样的东西应该工作:

#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

基本上,您从父视图控制器的 prepareForSegue 委托调用中的嵌入 segue 中捕获 EmbeddedTableViewController,然后在 viewDidAppear 中,将 tableview 控制器中的 parentNextButton 设置为父 nextButton。这将负责启用/禁用下一个按钮。

至于您的“在 RootViewController 中的操作”,您对您正在尝试做的事情的描述对我来说有点不清楚。我猜要填写的值在表格视图中。如果是这样,请将所有逻辑放在嵌入式 tableview 控制器中,并根据需要切换下一个按钮的启用状态。

于 2013-10-30T16:37:57.533 回答
0

每当我遇到这类问题时,我都会用事件来解决它。

  1. 使用 NSNotificationCenter 从您的代表发布事件
  2. 在您的 RootViewController 中为该事件添加一个侦听器。
于 2013-10-30T16:41:41.400 回答