Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在Xcode中如何抑制;“执行不完整”;?(遗产)_Iphone_Ios_Xcode_Inheritance - Fatal编程技术网

Iphone 在Xcode中如何抑制;“执行不完整”;?(遗产)

Iphone 在Xcode中如何抑制;“执行不完整”;?(遗产),iphone,ios,xcode,inheritance,Iphone,Ios,Xcode,Inheritance,我有一个方法,它是在它的超级方法中实现的。当我运行我的程序时。它很好用。如何抑制此警告?顺便说一下,这两种方法都在.m文件中 代码如下所示: A.m级 @interface ClassA() - (void)method; @end @interface ClassA @end @implementation ClassA - (void)doStuff { //Call 'Method' [self method]; } @end @interface Class

我有一个方法,它是在它的超级方法中实现的。当我运行我的程序时。它很好用。如何抑制此警告?顺便说一下,这两种方法都在.m文件中

代码如下所示:

A.m级

@interface ClassA()
- (void)method;
@end
@interface ClassA
@end

@implementation ClassA
- (void)doStuff
{
   //Call 'Method'       
  [self method];
}
@end
@interface ClassA()
@end
@implementation ClassA
- (void)method
{
    //do your stuff here
}
@end
A.h级

@interface ClassA : ClassB
@end
@interface ClassA : ClassB  
//ClassB inherits from Class A, so we define 'method' in Class B
//ClassA knows about 'method' by inheritance from class B,
//so 'method' doesn't need to be defined here.

//doStuff will be the method that calls 'method'
- (void)doStuff;
@end
@interface ClassA : ClassB
@end
@interface ClassA : ClassB
@end
B.m级

@interface ClassB()
@end
@implementation ClassB
- (void)method
{
}
@interface ClassB
@end

@implementation ClassB
- (void)method
{
   //'method' does it's thing       
  NSLog(@"Method has been Called");
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do nothing or even assert false
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do your stuff here
}
@end

当我调用ClassA中的方法时,它工作正常,不管怎样,您都可以实现该方法,并调用超级方法-

-(void)doMyThing {

    [super doMyThing];

    // do nothing

}

听起来像是在.h文件中声明了不应该声明的方法?或者,.h文件中缺少@end

你没有给我们太多的支持。我们可以从.h和.m中查看您的完整代码吗


阅读代码示例后,请尝试以下操作:

A.h级

@interface ClassA : ClassB
@end
@interface ClassA : ClassB  
//ClassB inherits from Class A, so we define 'method' in Class B
//ClassA knows about 'method' by inheritance from class B,
//so 'method' doesn't need to be defined here.

//doStuff will be the method that calls 'method'
- (void)doStuff;
@end
@interface ClassA : ClassB
@end
@interface ClassA : ClassB
@end
A.m级

@interface ClassA()
- (void)method;
@end
@interface ClassA
@end

@implementation ClassA
- (void)doStuff
{
   //Call 'Method'       
  [self method];
}
@end
@interface ClassA()
@end
@implementation ClassA
- (void)method
{
    //do your stuff here
}
@end
B.h类

@interface ClassB  
//Define 'method' which will be inherited by ClassA 
- (void)method;
@end
@interface ClassB
- (void)method;
@end
@interface ClassB
- (void)method;
@end
B.m级

@interface ClassB()
@end
@implementation ClassB
- (void)method
{
}
@interface ClassB
@end

@implementation ClassB
- (void)method
{
   //'method' does it's thing       
  NSLog(@"Method has been Called");
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do nothing or even assert false
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do your stuff here
}
@end

你完全错了。流行的结构是:

B.h类

@interface ClassB  
//Define 'method' which will be inherited by ClassA 
- (void)method;
@end
@interface ClassB
- (void)method;
@end
@interface ClassB
- (void)method;
@end
B.m级

@interface ClassB()
@end
@implementation ClassB
- (void)method
{
}
@interface ClassB
@end

@implementation ClassB
- (void)method
{
   //'method' does it's thing       
  NSLog(@"Method has been Called");
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do nothing or even assert false
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do your stuff here
}
@end
A.h级

@interface ClassA : ClassB
@end
@interface ClassA : ClassB  
//ClassB inherits from Class A, so we define 'method' in Class B
//ClassA knows about 'method' by inheritance from class B,
//so 'method' doesn't need to be defined here.

//doStuff will be the method that calls 'method'
- (void)doStuff;
@end
@interface ClassA : ClassB
@end
@interface ClassA : ClassB
@end
A.m级

@interface ClassA()
- (void)method;
@end
@interface ClassA
@end

@implementation ClassA
- (void)doStuff
{
   //Call 'Method'       
  [self method];
}
@end
@interface ClassA()
@end
@implementation ClassA
- (void)method
{
    //do your stuff here
}
@end
这就是所谓的方法重写。但如果我正确理解了你想要实现的目标,你应该:

B.h类

@interface ClassB  
//Define 'method' which will be inherited by ClassA 
- (void)method;
@end
@interface ClassB
- (void)method;
@end
@interface ClassB
- (void)method;
@end
B.m级

@interface ClassB()
@end
@implementation ClassB
- (void)method
{
}
@interface ClassB
@end

@implementation ClassB
- (void)method
{
   //'method' does it's thing       
  NSLog(@"Method has been Called");
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do nothing or even assert false
}
@end
@interface ClassB()
@end
@implementation ClassB
- (void)method
{
    //do your stuff here
}
@end
A.h级

@interface ClassA : ClassB
@end
@interface ClassA : ClassB  
//ClassB inherits from Class A, so we define 'method' in Class B
//ClassA knows about 'method' by inheritance from class B,
//so 'method' doesn't need to be defined here.

//doStuff will be the method that calls 'method'
- (void)doStuff;
@end
@interface ClassA : ClassB
@end
@interface ClassA : ClassB
@end
也没有必要搞砸ClassA,你可以打电话

ClassA *o=[[ClassA alloc ] init];
[o method];

然后,由于从ClassB继承,
方法
在classA中可用

发布一些代码,没有它,你的问题是unclear@MichałZygar,这很清楚。我在一个类中有一个方法,实现在它的超类中。我不这么认为。好像你在那里建造了一些奇怪的建筑。无论如何为什么有一个方法在超类中实现并在派生类中声明?为什么不把这个方法的声明放在超类头文件中呢?然后您可以直接从派生类调用此方法。@MichałZygar,谢谢您为我解释这一点。我添加了代码。也许协议是更好的解决方案!但它是在.m文件中定义的。编译器没有看到它。您的意思是无法将该方法放入“.m”文件中?但我的应用程序实际上正在运行。这是为什么呢?好吧,它是有效的,因为方法是在那里定义的(尽管没有定义)。但是,如果您在.m文件中放置了一个方法声明,那么该声明将仅在该.m文件中可见,并隐藏(未声明)在其他任何地方。因此,您现在拥有的是:调用了classB中的方法,但没有声明它(这就像一个幸运的机会)。classA中的方法已声明但未定义(没有实现),因此编译器缺少该方法。有时无法执行此操作,例如,当类A具有您希望使用的动态属性时。