感谢您花时间阅读我的问题并帮助我:)
我正在构建一个 TabView 项目,在应用程序的选项卡 3 上我有一排专辑,在专辑 3 的第 1 页中,nextButton 将用户带到专辑的第 2 页。Page 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 和 #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"。
奇怪!我实际上在第二个选项卡中有完全相同的代码工作,我用它在视图之间切换没有任何问题。那么为什么它在这里不起作用?!?!
请帮助我卡住 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