【发布时间】:2011-12-20 15:07:05
【问题描述】:
我正在调整 This tutorial 以适应我的应用程序,但我已经把它归结为最后一个错误,这让我停止了前进。程序无法在另一个文件中找到属性,但该属性已明确定义。这是有问题的代码:
实际错误行:
for (DTContact *dtc in _dtContact.contact) {
文件的 .h 和相关项目:
#import <UIKit/UIKit.h>
@class XMLTestViewController;
@class DTCXMLResponse;
@interface XMLTestController : UIViewController{
UIWindow *window;
XMLTestViewController *viewController;
DTCXMLResponse *_dtContact;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet XMLTestViewController *viewController;
@property (nonatomic, retain) DTCXMLResponse *dtContact;
@property (nonatomic, retain) IBOutlet UIButton *mybutton;
-(IBAction)buttonClicked;
@end
_dtContact.contact 存在问题。它在文件 DTCXMLResponse 中找不到联系人。这是 .h 文件和 .m 的部分:
.h
#import <Foundation/Foundation.h>
@interface DTContactXMLResponse : NSObject {
NSMutableArray *_contact;
}
@property (nonatomic, retain) NSMutableArray *contact;
@end
.m
#import "DTCXMLResponse.h"
@implementation DTContactXMLResponse
@synthesize contact = _contact;
- (id)init {
if ((self = [super init])) {
self.contact = [[NSMutableArray alloc] init];
}
return self;
}
@end
就是这样。如您所见,我在 DTCXMLResponse.h 中设置了“联系人”属性,并在 .m 中进行了链接。
【问题讨论】:
-
请注意,
self.contact = [[NSMutableArray alloc] init];行实际上应该是self.contact = [NSMutableArray array];,因为您的属性已经保留了数组。 -
我已经解决了,谢谢。
标签: ios xml properties gdataxml