本文介绍了NSXMLParserDelegate编译问题 - iPhone SDK 30. vs 4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的头文件定义如下:

#import <Foundation/Foundation.h>

@interface Warning: NSObject  { 

在我的.m文件中我做:

In my .m file I do:

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];

这个编译并在3.0以下工作正常。

This compiles and works just fine under 3.0.

如果我尝试使用4.0编译,我会收到此错误:

If I try to compile with 4.0 I get this error:

如果我添加:

@interface Warning: NSObject <NSXMLParserDelegate>  { 

它用4.0编译好,但是当我尝试用3.0编译时,我得到:

It compiles fine with 4.0, but when I try to compile with 3.0 I get:

正确找到Foundation框架。添加NSXMLParser.h无济于事。

The Foundation framework is found correctly. Adding NSXMLParser.h doesn't help.

任何帮助都将不胜感激。

Any help would be appreciated.

谢谢

推荐答案

根据库参考文档,NSXMLParser不需要严格的NSXMLParserDelegate实现:

According to the library reference documentation, NSXMLParser doesn't require a strict NSXMLParserDelegate implementation :

- (void)setDelegate:(id)delegate
- (id)delegate

NSXMLParser动态检查所需的委托方法可用性。

NSXMLParser checks needed delegate methods availability on the fly.

如果NSXMLParser需要NSXMLParserDelegate完全实现,则访问者将是:

If NSXMLParser was requiring a NSXMLParserDelegate full implementation, the accessors would be :

- (void)setDelegate:(id<NSXMLParserDelegate>)delegate
- (id<NSXMLParserDelegate>)delegate

我猜这就是为什么框架中没有实际定义的NSXMLParserDelegate协议。

I guess that's why there is no NSXMLParserDelegate protocol actually defined in the framework.

所以,这个界面对我来说似乎是正确的:

So, that interface seems correct to me :

#import <Foundation/Foundation.h>

@interface Warning: NSObject  { 

你所要做的就是实施你需要的 。

All you have to do is implement the delegate methods you need for.

编辑:

您可以尝试使用预处理器宏来激活或停用协议使用声明:

You could try using preprocessor macros to activate or deactivate the protocol usage declaration :

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
@interface Warning: NSObject <NSXMLParserDelegate>
#else
@interface Warning: NSObject
#endif
{
   // interface definition ...

我没有尝试使用4.0,但它适用于3.1和3.2之间的另一个例子

I didn't try this with 4.0, but it worked on another example between 3.1 and 3.2

这篇关于NSXMLParserDelegate编译问题 - iPhone SDK 30. vs 4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:06