gpt4 book ai didi

objective-c - 进行类扩展时避免警告

转载 作者:行者123 更新时间:2023-12-03 17:30:20 25 4
gpt4 key购买 nike

我想做以下事情:

@interface UINavigationController ()

-(void)removeFromNavigationStack:(Class)aClass;

@end

在 .m 文件中

@implementation UINavigationController

-(void)removeFromNavigationStack:(Class)aClass {

}

但是在 .m 文件中有很多警告,例如“找不到'initWithRootViewController:'的方法定义”

如何避免这种情况?我尝试过包含但仍然有警告

谢谢

最佳答案

由于您正在处理 UIKit 类 UINavigationController,因此您可能想要使用类别。扩展需要在类实现的主 @implementation block 中定义,并且您无权访问 UINavigationController

来自docs :

Class extensions are like anonymous categories, except that the methods they declare must be implemented in the main @implementation block for the corresponding class. Using the Clang/LLVM 2.0 compiler, you can also declare properties and instance variables in a class extension.

关于objective-c - 进行类扩展时避免警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11562991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com