您需要设置委托。让我证明:
`SVC.h`
@interface SVC
{
id _delegate;
}
- (void)setDelegate:(id)delegate; //sets the delegate
- (id)delegate; //gets the delegate
@end
@protocol SVCDelegate
- (void)sendCoordinates:(SVC *)svc;
@end
然后,在SVC.m
,你打电话委托在完全相同的方式,你在你的问题表明,这样[[self delegate] sendCoordinates:self];
现在,在FVC
,你需要#import SVC.h
和初始化对象。
SVC*svcObject = [[SVC alloc] init];
[svcObject setDelegate:self]; //self now refers to FVC - I think you're missing this one
//work with the object and when you're done, get rid of it in dealloc:
[svcObject setDelegate:nil];
[svcObject release];
在同一个类中,实现- (void)sendCoordinates:(SVC *)svc
并设置委托后,它会被称为。
我想你错过了setDelegate:
阶段,这就是为什么它不起作用。
希望它有帮助!
注意:在SVC中,请记住保留该委托,否则它将变为nil
并且不会调用委托方法。不要忘记一旦完成就释放该代表。
无论你解释的是完美的。但这里的情况有点棘手。要设置委托我必须移动到“FVC”比我只能设置委托。程序计数器现在在“SVC”中。 – Harsh
移动FVC?你是什么意思? – Pripyat
现在程序计数器(PC)在“SVC”中。我想通过“FVC”中的信息。为此,我必须设置“FVC”作为代表。代码将正常工作。但对于那台PC必须跳到“FVC”。它将如何发生? – Harsh