我遇到了一个奇怪的问题,我需要从另一个名为void的类中调用一个名为insertCommunication的insertCommunication函数,这个函数包含在一个名为MBUser.m的类文件中。由于这个函数不是在ProdottoViewController中,而是在MBUser.m中,所以我需要执行这些步骤才能正确导入类,如果我错了,请纠正我:
.h中导入MBUser的ProdottoViewController.m文件,如下所示:
#导入"ProdottoViewController.h“#导入"MBUser.h”@ ProdottoViewController ()接口{}@class of MBUser,如下所示:
@class MBUser;/*这个类声明放在ProdottoViewController.m*/的#import和@Interface之间。@property of MBUser in ProdottoViewController.m
@property (强的,非原子的) MBUser *userClass;alloc和init-alize MBUser,在本例中,我是在viewDidLoad函数中这样做的:这段代码工作正常,编译和Xcode完全没有错误,但是当我试图调用函数时,它会返回nil,甚至MBUser中的其他对象,即使正确地分配了MBUser (如这里所示):

你能帮帮我吗?
编辑:MBUser.m的init方法
- (id)init {
self = [super init];
if (self) {
dispatch_once(&onceToken, ^{
dictCache = [[NSMutableDictionary alloc] init];
});
logined = NO;
allowLogin = YES;
}
return self;
}发布于 2015-04-17 13:30:03
解决方案是只在需要时使用alloc和init-alize,而不是在viewDidLoad函数中使用MBUser类。不过,我在问题中贴出的步骤是正确的。谢谢大家。
发布于 2015-04-01 09:34:01
- (void)dealloc类中添加dealloc方法(dealloc method,- (void)dealloc),并将其放置在断点上,以检查何时将其解除分配。https://stackoverflow.com/questions/29386295
复制相似问题