如果没有替代方法,则禁止使用已弃用方法的警告

我在一个项目中实现了这个自定义类: https : //github.com/wimagguc/ios-custom-alertview

但Xcode给出了一个警告,“initWithParentView”已被弃用。

- (id)init { return [self initWithParentView:NULL]; } 

我一直没能find这种方法的替代品,class级出色。 有人可以告诉我如何抑制这个警告或告诉我一个替代“initWithParentView”?

请阅读更改说明,清楚地说明使用init方法

编辑:因为它在无限循环中使用[super init]而不是[self init]

 - (id)init { // return [self init]; return [super init]; } 

它看起来像开发人员将其标记为已弃用,并build议使用init方法。 您可以编辑第三方库以删除此属性或将其禁用。 也许把initWithParentView的内容移动到init中会更好的修复这个库。

 /*! DEPRECATED: Use the [CustomIOS7AlertView init] method without passing a parent view. */ - (id)initWithParentView: (UIView *)_parentView __attribute__ ((deprecated)); 
 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void) methodUsingDeprecatedStuff { //use deprecated stuff } #pragma clang diagnostic pop 

这应该压制它。

那么class级的* .h告诉你该怎么做

/ *! DEPRECATED:在不传递父视图的情况下使用[CustomIOS7AlertView init]方法。 * /

所以,如果你重写了自定义类的使用

 [self init]; 

别的用途

 [[CustomIOS7AlertView alloc] init]