我有一个超类 SuperClassYeh 和一个子类 SubClassYeh。inheritTest我在 SuperClassYeh 中有方法,我inheritTest在 SubClassYeh 中覆盖。我通过调用testSuperAndSelfSubClassYeh 中的方法启动程序运行。此方法将调用fromYEHSuperClassYeh 中的另一个方法。在fromYEH,我想打电话给inheritTestSuperClassYeh。我怎么做?使用[self inheritTest]调用inheritTestSubClassYeh,而不是 SuperClassYeh。
这是启动整个运行的代码片段
SubClassYeh *testing = [[SubClassYeh alloc] init];
[testing testSuperAndSelf];
这是 SuperClassYeh 的代码片段
- (void) fromYEH
{
[self inheritTest]; //Calls the inheritTest in SubClassYeh, not SuperClassYeh
}
- (void) inheritTest
{
NSLog(@"Testing Indicator. Inside SuperClassYEH inheritTest");
}
这是 SubClassYeh 的代码片段
- (void) inheritTest
{
NSLog(@"Testing Indicator. Inside SubClassYeh inheritTest");
}
- (void) testSuperAndSelf
{
[super fromYEH];
}