gpt4 book ai didi

ios - 如何从嵌入式 TableView 调用 RootViewController 中的操作?

转载 作者:行者123 更新时间:2023-11-29 03:31:41 24 4
gpt4 key购买 nike

我有一个 Storyboard应用程序,在 Root View Controller 的容器中嵌入了表格 View 。用户将通过嵌入表格 View 中的弹出窗口做出一些选择。做出所有选择后,我希望激活 Root View Controller View 中的“下一个”按钮(未变暗),以便用户可以触摸它。

当我可以完成这项工作时,我在 RootViewController 中放置了一个操作 - 检查是否所有值都已归档,如果是,则撤消按钮,如果注意到,则将其调暗。但我该如何称呼这个 Action 呢?每当用户做出选择时,我的代表就会被解雇,所以看起来他就是我调用该操作的地方,但它不可用。

任何帮助将不胜感激。

布莱恩

这是一些代码:

#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

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

实现

#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

好的,我仍然遇到问题。我很抱歉,我确信这是愚蠢的事情。

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

#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 没有“看到”该文件,因此无法获取该属性。

最佳答案

像这样的东西应该可以工作:

#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

基本上,您从父 View Controller 中的 prepareForSegue 委托(delegate)调用中的嵌入 segue 捕获 EmbeddedTableViewController,然后在 viewDidAppear 中,将 TableView Controller 中的 parentNextButton 设置为父级 nextButton。这将负责启用/禁用下一个按钮。

至于您的“RootViewController 中的操作”,您对您尝试执行的操作的描述对我来说有点不清楚。我猜测要填写的值在 TableView 中。如果是这样,请将所有逻辑放在嵌入式 tableview Controller 中,并根据需要切换下一个按钮的启用状态。

关于ios - 如何从嵌入式 TableView 调用 RootViewController 中的操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19687007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com