簡體   English   中英

類消息的Receiver'ViewController'是appdelegate類中的前向聲明錯誤

[英]Receiver 'ViewController' for class message is a forward declaration error in appdelegate class

我使用了s hareddelegate方法,在運行app時我得到了Unknown類型名稱'ViewController' ; 你是說'UIViewController'嗎? 然后我使用@class ViewController但現在我得到了上面的錯誤我該如何解決。

在下面的@property(nonatomic,strong) nstring *title1; 我在tableview中使用它來分享數據到detailview。

請幫我。

#import <UIKit/UIKit.h>
//#import "ViewController.h"

@class ViewController;
#define UIAPPDelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{

}

@property(strong,nonatomic) NSString *title1;
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic) BOOL isFirstTime;
@property (strong, nonatomic) ViewController *viewController;
//@property(strong,nonatomic) ViewController *viewController;
@property (strong, nonatomic) UINavigationController *navigationController;

@end

//did finish with lanching page.
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    isFirstTime = YES;

    sleep(3);

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    title1=[[NSString alloc]init];
    self.viewController= [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

在使用.m文件之前,必須先添加它。

@class將用於通知編譯器

“我有那個viewController類,不要指望我導入.h文件”

編譯說

“好的。我沒有。但你必須先導入它,然后在使用之前讓我知道。”

因此,在.m文件中使用它之前,您必須在使用.m文件之前添加/導入它。

 #import "ViewController.h"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM