我在需要从其他类访问的类“loadingViewController”上有一个函数。我第一次调用如下函数时,它可以工作,但是如果我从另一个类再次调用它,不要因为再次分配它并重置参数。如果我创建一个实例方法也是如此。如何简单地从另一个类调用一个函数而不进行初始化或再次分配?可能是基本的新手问题...谢谢。
类在标题中声明并正确合成。
self.loadingController = [[loadingViewController alloc] initWithNibName:@"loadingViewController" bundle:nil];
[loadingController incrementProgress:0.1];
最佳答案
如果没有看到更多代码,很难确定,但我认为您只需要确保只初始化 loadingController
一次:
if ( self.loadingController == nil ) {
self.loadingController = [[loadingViewController alloc] initWithNibName:@"loadingViewController" bundle:nil];
}
[self.loadingController incrementProgress:0.1];
关于iphone - 另一个类的objective-c调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10130170/