Tôi đang điều chỉnh This tutorial cho ứng dụng của mình và tôi đã xóa nó xuống một lỗi cuối cùng, điều này đang ngăn tôi theo dõi. Chương trình không thể tìm thấy thuộc tính trong tệp khác, nhưng thuộc tính đó được xác định rõ ràng. Đây là mã trong câu hỏi:Không thể tìm thấy thuộc tính trong đối tượng lớp học chuyển tiếp
Dòng lỗi thực tế:
for (DTContact *dtc in _dtContact.contact) {
các .h cho các tập tin, và các mặt hàng trong câu hỏi:
#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
Nó gặp vấn đề với _dtContact.contact . Nó không thể tìm thấy liên hệ trong tệp DTCXMLResponse. Dưới đây là file .h và phần của .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
Vì vậy, theres đó. Như bạn có thể thấy, tôi có 'liên hệ' được gắn thích hợp trong DTCXMLResponse.h và được liên kết trong .m.
Một lưu ý, dòng 'self.contact = [[NSMutableArray alloc] init];' nên thực sự 'self.contact = [mảng NSMutableArray];', vì thuộc tính của bạn đã giữ lại mảng. –
Tôi đã khắc phục điều đó, cảm ơn bạn. –