IOS未知typename appdelegate

时间:2015-06-03 10:37:37

标签: ios objective-c

我收到错误,如

  

:未知的类型名称' AppDelegate'

     

:未知的类型名称' AppDelegate'

     

:财产“弱”'属性必须是对象类型

Error Image

我已经提到了很多像这样的问题,但都给出了像添加

这样的答案
@class Appdelegate;

我尝试编辑此代码,但在此之后它会出现错误,如

  

:AppDelegate.m:23:18:重新定义' ddLogLevel'

Refined Log

因为此日志是在两个视图控制器中定义的。我也尝试从上面的视图控制器评论此日志的行,但然后它将给出错误

  

:/ChatViewController.m:440:13:使用未声明的标识符' ddLogLevel'

DDLOG Error

现在解决方法是什么?

编辑:我必须这样声明。因为我正在研究xmpp。所以我必须在另一个视图控制器中调用[[self appDelegate] connect]方法。

- (AppDelegate *)appDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}

修改

      //Appdelegate.h file //
    #import <UIKit/UIKit.h>
    #import <CoreData/CoreData.h>
    #import "ViewController.h"
  #import "MBProgressHUD.h"
  #import "FriendsViewController.h"
  #import <CoreData/CoreData.h>
 #import "XMPPFramework.h"
//@class FriendsViewController;
@class ViewController;
   @interface AppDelegate :  NSObject <UIApplicationDelegate, XMPPRosterDelegate>
 {
XMPPStream *xmppStream;
XMPPReconnect *xmppReconnect;
XMPPRoster *xmppRoster;
XMPPRosterCoreDataStorage *xmppRosterStorage;
XMPPvCardCoreDataStorage *xmppvCardStorage;
XMPPvCardTempModule *xmppvCardTempModule;
XMPPvCardAvatarModule *xmppvCardAvatarModule;
XMPPCapabilities *xmppCapabilities;
XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;

NSString *password;

BOOL customCertEvaluation;

BOOL isXmppConnected;
BOOL isauthenticate;

UIWindow *window;
UINavigationController *navigationController;
//SettingsViewController *loginViewController;
UIBarButtonItem *loginButton;
ViewController *viewController;
FriendsViewController *FriendsViewController;
  }
 @property (strong, nonatomic) UIWindow *window;
 @property (nonatomic, strong, readonly) XMPPStream *xmppStream;
 @property (nonatomic, strong, readonly) XMPPReconnect *xmppReconnect;
 @property (nonatomic, strong, readonly) XMPPRoster *xmppRoster;
 @property (nonatomic, strong, readonly) XMPPRosterCoreDataStorage  *xmppRosterStorage;
 @property (nonatomic, strong, readonly) XMPPvCardTempModule *xmppvCardTempModule;
 @property (nonatomic, strong, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
 @property (nonatomic, strong, readonly) XMPPCapabilities *xmppCapabilities;
 @property (nonatomic, strong, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;

//@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) IBOutlet UINavigationController *navigationController;
//@property (nonatomic, strong) IBOutlet SettingsViewController *settingsViewController;
@property (nonatomic, strong) IBOutlet UIBarButtonItem *loginButton;
@property (nonatomic, strong) ViewController *viewController;
@property (nonatomic, strong) FriendsViewController *FriendsViewController;
  - (NSManagedObjectContext *)managedObjectContext_roster;
  - (NSManagedObjectContext *)managedObjectContext_capabilities;
  @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
  - (BOOL)connect;
  - (BOOL) isXmppConnected;
  - (void)disconnect;
  -(BOOL) isauthenticate;

 @end

2 个答案:

答案 0 :(得分:6)

你有两个问题,我将分别解决:

  

未知的类型名称&#39; AppDelegate&#39;

这是因为循环依赖:ChathistryViewController.h导入AppDelegate.h,反之亦然。

您可以仅在AppDelegate.h导入ChathistryViewController.m并在@class AppDelegate文件中包含.h来解决此问题。

  

AppDelegate.m:23:18:重新定义&#39; ddLogLevel&#39;

当您在ddLogLevel文件中定义*ViewController.h时,其定义为&#34;已复制&#34;到您导入的所有文件*ViewController.h

您应该导入CocoaLumberjack并仅在ddLogLevel个文件中定义.m,因为.h中不需要它们。

答案 1 :(得分:2)

应该像这样创建Appdelegate对象:

它是一个单线类,当前进程只存在一个类的实例。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];