ルート ビュー コントローラーのコンテナーにテーブル ビューが埋め込まれたストーリーボード アプリがあります。ユーザーは、埋め込まれたテーブル ビューのポップアップを介していくつかの選択を行います。すべての選択が完了したら、ルート ビュー コントローラーのビューの [次へ] ボタンをアクティブにして (淡色表示を解除して)、ユーザーがタッチできるようにします。
この作業ができるようになったら、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
OK、まだ問題があります。申し訳ありませんが、それは愚かなことだと確信しています。
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;
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;
}
私が得るエラーは、このコード行にあります:
//self.eTableViewController.parentNexButton = self.btnNext;
エラーは
タイプ「UITableViewController *」のオブジェクトにプロパティ「parentNextButton」が見つかりません
これは、eTableViewController がファイルを「見ていない」ため、そのプロパティを取得できないことを示していると思います。