我收到错误,如
:未知的类型名称' AppDelegate'
:未知的类型名称' AppDelegate'
:财产“弱”'属性必须是对象类型
我已经提到了很多像这样的问题,但都给出了像添加
这样的答案@class Appdelegate;
我尝试编辑此代码,但在此之后它会出现错误,如
:AppDelegate.m:23:18:重新定义' ddLogLevel'
因为此日志是在两个视图控制器中定义的。我也尝试从上面的视图控制器评论此日志的行,但然后它将给出错误
:/ChatViewController.m:440:13:使用未声明的标识符' ddLogLevel'
现在解决方法是什么?
编辑:我必须这样声明。因为我正在研究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
答案 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];