私の問題を読んで助けてくれてありがとう:)
私はTabViewプロジェクトを構築しており、アプリのタブ3にアルバムの行があり、アルバム3のページ1でnextButtonがユーザーをアルバムのページ2に移動させます。ページ 2 には、backPage (ページ 1 に戻る) や backButton (アルバム選択ページに戻る) などのボタンがあります。
エラー:
A3Page2ViewController.m:92:49: Property 'view' cannot be found in forward class object 'A3Page1ViewController'
警告:
A3Page2ViewController.m:91:28: Receiver 'A3Page1ViewController' is a forward class and corresponding @interface may not exist
私はこのサイトと他のサイトを検索しましたが、ほとんどの回答は @Class をヘッダー filw で使用する方法と #import ".h" を .m ファイルでのみ使用する方法に関連しています。コードを確認し、ルールに従っていたのに、まだ機能しないのはなぜですか?
これは私がやったことです:これは明らかにエラーを起こしている関数(A3Page2ViewController内)です...
-(IBAction)backPage:(id)sender
{
a3Page1ViewController = [[A3Page1ViewController alloc]initWithNibName:@"A3Page1ViewController"bundle:nil];
[self.view addSubview:a3Page1ViewController.view];
}
コメントアウトすると、アプリは正常に実行され、すべてのビューが読み込まれ、backButton を含むすべてのボタンが機能することに注意してください。コメントを外すと、ビルドが拒否され、エラーが発生します。
以下に、A3Page1ViewController と A3Page2ViewController の両方の .h ファイルと .m ファイルをリストします。
@class と #import ".h" が正しい場所にあることがわかります。
奇妙!! 私は実際に2番目のタブでまったく同じコードを使用しています。これを使用して、問題なくビューを切り替えます。では、なぜここで機能しないのですか?!?!
助けてください ATM で立ち往生しています。理由がわかりません:/
A3Page1ViewController.h
#import <UIKit/UIKit.h>
@class A3Page2ViewController;
@class ThirdViewController;
@class A3P1;
@class A3P2;
@class A3P3;
@interface A3Page1ViewController : UIViewController {
A3Page2ViewController*a3Page2ViewController;
ThirdViewController*thirdViewController;
A3P1*A3P1;
A3P2*A3P2;
A3P3*A3P3;
UIButton *button1;
UIButton *button2;
UIButton *button3;
UIButton *nextButton;
UIButton *backButton;
}
@property(nonatomic,retain) IBOutlet A3Page2ViewController *a3Page2ViewController;
@property(nonatomic,retain) IBOutlet ThirdViewController *thirdViewController;
@property(nonatomic,retain) IBOutlet A3P1 *a3P1;
@property(nonatomic,retain) IBOutlet A3P2 *a3P2;
@property(nonatomic,retain) IBOutlet A3P3 *a3P3;
@property (nonatomic, retain) IBOutlet UILabel *logoLabel;
@property (nonatomic, retain) IBOutlet UILabel *descriptionLabel;
@property (nonatomic, retain) IBOutlet UILabel *copyrightLabel;
@property(nonatomic,retain) IBOutlet UIButton *button1;
@property(nonatomic,retain) IBOutlet UIButton *button2;
@property(nonatomic,retain) IBOutlet UIButton *button3;
@property(nonatomic,retain) IBOutlet UIButton *nextButton;
@property(nonatomic,retain) IBOutlet UIButton *backButton;
-(IBAction)FirstButton:(id)sender;
-(IBAction)SecondButton:(id)sender;
-(IBAction)ThirdButton:(id)sender;
-(IBAction)nextPage:(id)sender;
-(IBAction)backButton:(id)sender;
@end
A3Page1ViewController.m
#import "A3Page1ViewController.h"
#import "FXLabel.h"
#import <QuartzCore/QuartzCore.h>
#import "A3Page2ViewController.h"
#import "ThirdViewController.h"
#import "A3P1.h"
#import "A3P2.h"
#import "A3P3.h"
@implementation A3Page1ViewController
@synthesize a3Page2ViewController,thirdViewController,a3P1 ,a3P2 ,a3P3 , logoLabel, descriptionLabel, button1,button2,button3,nextButton,backButton, copyrightLabel;
-(UILabel*)createLabelWithFrame:(CGRect)frame andFontSize:(float)fontSize andText:(NSString*)text
{
UILabel* label = [[UILabel alloc] initWithFrame:frame];
[label setFont:[UIFont systemFontOfSize:fontSize]];
[label setTextColor:[UIColor whiteColor]];
[label setShadowColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(0, -1)];
//[label setTextAlignment:UITextAlignmentCenter];
[label setBackgroundColor:[UIColor clearColor]];
[label setText:text];
return label;
}
-(IBAction)FirstButton:(id)sender
{
a3P1 = [[A3P1 alloc]initWithNibName:@"A3P1"bundle:nil];
[self.view addSubview:a3P1.view];
}
-(IBAction)SecondButton:(id)sender
{
a3P2 = [[A3P2 alloc]initWithNibName:@"A3P2"bundle:nil];
[self.view addSubview:a3P2.view];
}
-(IBAction)ThirdButton:(id)sender
{
a3P3 = [[A3P3 alloc]initWithNibName:@"A3P3"bundle:nil];
[self.view addSubview:a3P3.view];
}
-(IBAction)backButton:(id)sender
{
thirdViewController = [[ThirdViewController alloc]initWithNibName:@"ThirdView"bundle:nil];
[self.view addSubview:thirdViewController.view];
}
-(IBAction)nextPage:(id)sender
{
a3Page2ViewController = [[A3Page2ViewController alloc]initWithNibName:@"A3Page2ViewController"bundle:nil];
[self.view addSubview:a3Page2ViewController.view];
}
- (void)viewDidLoad
{
//CGRectMake(x,y,width,height);
// Do any additional setup after loading the view, typically from a nib.
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
A3Page2ViewController.h
@class A3Page1ViewController;
@class ThirdViewController;
@class A3P10;
@class A3P11;
@class A3P12;
@interface A3Page2ViewController : UIViewController {
A3Page1ViewController*a3Page1ViewController;
ThirdViewController*thirdViewController;
A3P10*a3P10;
A3P11*a3P11;
A3P12*a3P12;
UIButton *button1;
UIButton *button2;
UIButton *button3;
UIButton *backButton;
UIButton *backPage;
}
@property(nonatomic,retain) IBOutlet A3Page1ViewController *a3Page1ViewController;
@property(nonatomic,retain) IBOutlet ThirdViewController *thirdViewController;
@property(nonatomic,retain) IBOutlet A3P10 *a3P10;
@property(nonatomic,retain) IBOutlet A3P11 *a3P11;
@property(nonatomic,retain) IBOutlet A3P12 *a3P12;
@property(nonatomic,retain) IBOutlet UIButton *button1;
@property(nonatomic,retain) IBOutlet UIButton *button2;
@property(nonatomic,retain) IBOutlet UIButton *button3;
@property(nonatomic,retain) IBOutlet UIButton *backButton;
@property(nonatomic,retain) IBOutlet UIButton *backPage;
-(IBAction)FirstButton:(id)sender;
-(IBAction)SecondButton:(id)sender;
-(IBAction)ThirdButton:(id)sender;
-(IBAction)backButton:(id)sender;
-(IBAction)backPage:(id)sender;
@end
A3Page2ViewController.m
#import "A3Page1ViewController.h"
#import "FXLabel.h"
#import <QuartzCore/QuartzCore.h>
#import "A3Page2ViewController.h"
#import "ThirdViewController.h"
#import "A3P10.h"
#import "A3P11.h"
#import "A3P12.h"
@implementation A3Page2ViewController
@synthesize thirdViewController,a3Page1ViewController,a3P10 ,a3P11 ,a3P12, backButton,backPage, button1,button2,button3;
-(UILabel*)createLabelWithFrame:(CGRect)frame andFontSize:(float)fontSize andText:(NSString*)text
{
UILabel* label = [[UILabel alloc] initWithFrame:frame];
[label setFont:[UIFont systemFontOfSize:fontSize]];
[label setTextColor:[UIColor whiteColor]];
[label setShadowColor:[UIColor blackColor]];
[label setShadowOffset:CGSizeMake(0, -1)];
// [label setTextAlignment:UITextAlignmentCenter];
[label setBackgroundColor:[UIColor clearColor]];
[label setText:text];
return label;
}
-(IBAction)FirstButton:(id)sender
{
a3P10 = [[A3P10 alloc]initWithNibName:@"A3P10"bundle:nil];
[self.view addSubview:a3P10.view];
}
-(IBAction)SecondButton:(id)sender
{
a3P11 = [[A3P11 alloc]initWithNibName:@"A3P11"bundle:nil];
[self.view addSubview:a3P11.view];
}
-(IBAction)ThirdButton:(id)sender
{
a3P12 = [[A3P12 alloc]initWithNibName:@"A3P12"bundle:nil];
[self.view addSubview:a3P12.view];
}
-(IBAction)backButton:(id)sender
{
thirdViewController = [[ThirdViewController alloc]initWithNibName:@"ThirdView"bundle:nil];
[self.view addSubview:thirdViewController.view];
}
-(IBAction)backPage:(id)sender
{
//*****Alleged Error/Warning causing code=[********
a3Page1ViewController = [[A3Page1ViewController alloc]initWithNibName:@"A3Page1ViewController"bundle:nil];
[self.view addSubview:a3Page1ViewController.view];
}
- (void)viewDidLoad
{
//CGRectMake(x,y,width,height);
// Do any additional setup after loading the view, typically from a nib.
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end