那里。我有 2 节课
@implemention A
-(void) method1{
something;
}
@end
@implemention B
-(void) method2{
something
}
@end
如果A类的实现不能修改,有没有办法在调用A中的method1时调用B中的method2?
那里。我有 2 节课
@implemention A
-(void) method1{
something;
}
@end
@implemention B
-(void) method2{
something
}
@end
如果A类的实现不能修改,有没有办法在调用A中的method1时调用B中的method2?
It sounds like you are trying to something wierd, but without further information it's hard to give you alternate suggestions.
However. One way to do what that doesn't require changing the implementation of class A is to subclass class A and override the method implementation:
- method1 {
[super method1]; // forward the call on to class A
// Now you can do what ever you want
// Post a notification or call method1 on an instance of class B
}
添加viewDidLoad()
观察者_class B
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(method2) name:@"method1Executed" object:nil];
并添加method1()
以下class A
代码
[[NSNotificationCenter defaultCenter] postNotificationName:@"method1Executed" object:nil];
尝试这个
您可以在 Method1 中创建类对象
-(void) method1
{
B *b = [[B alloc] init ]; // Create object of class B
b.method2 // call method of class B
}