访问.h文件中声明的实体的属性

时间:2013-07-10 17:38:28

标签: objective-c xcode ios6 ios4

我是xCode的新手,我正在尝试使用我没写过的代码。很抱歉,如果这是一个愚蠢的问题!

运行我的代码后,我在这里创建实体(实体由Entities.h定义):

Entities *proxy = [[Entities alloc]initWithUri:@"http://localhost:8080/Resource/example.svc" credential:nil];
DataServiceQuery *qry = [proxy person];
QueryOperationResponse *result = [qry execute];
items = [result getResult];
NSLog(@"items size: %@", items);

这很有效并打印以下内容:

enter image description here

但是,我没有IDEA如何访问Model_person中的变量。

Entities.h的相关代码是:

/**
* @interface:person
* @Type:EntityType

* @key:person_id* 
*/
@interface Model_person : ODataObject
{

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_id;

/**
* @Type:EntityProperty
* @EdmType:Edm.String
* @MaxLength:255
* @FixedLength:
*/
NSString *m_person_role;

/**
* @Type:EntityProperty
* @EdmType:Edm.String
* @MaxLength:255
* @FixedLength:
*/
NSString *m_person_firstname;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_department;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_contractor;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_supervisor;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_admin;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_workweek;

/**
* @Type:EntityProperty
* @EdmType:Edm.String
* @MaxLength:255
* @FixedLength:
*/
NSString *m_person_employee_id;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_billrate;

/**
* @Type:EntityProperty
* @EdmType:Edm.String
* @MaxLength:255
* @FixedLength:
*/
NSString *m_person_lastname;

/**
* @Type:EntityProperty
* @EdmType:Edm.Int32
*/
NSNumber *m_person_active;

}


@property ( nonatomic , retain , getter=getperson_id , setter=setperson_id : )NSNumber   *m_person_id;
@property ( nonatomic , retain , getter=getperson_role , setter=setperson_role : ) NSString *m_person_role;
@property ( nonatomic , retain , getter=getperson_firstname , setter=setperson_firstname : ) NSString *m_person_firstname;
@property ( nonatomic , retain , getter=getperson_department , setter=setperson_department : )NSNumber *m_person_department;
@property ( nonatomic , retain , getter=getperson_contractor , setter=setperson_contractor : )NSNumber *m_person_contractor;
@property ( nonatomic , retain , getter=getperson_supervisor , setter=setperson_supervisor : )NSNumber *m_person_supervisor;
@property ( nonatomic , retain , getter=getperson_admin , setter=setperson_admin : )NSNumber *m_person_admin;
@property ( nonatomic , retain , getter=getperson_workweek , setter=setperson_workweek : )NSNumber *m_person_workweek;
@property ( nonatomic , retain , getter=getperson_employee_id , setter=setperson_employee_id : ) NSString *m_person_employee_id;
@property ( nonatomic , retain , getter=getperson_billrate , setter=setperson_billrate : )NSNumber *m_person_billrate;
@property ( nonatomic , retain , getter=getperson_lastname , setter=setperson_lastname : ) NSString *m_person_lastname;
@property ( nonatomic , retain , getter=getperson_active , setter=setperson_active : )NSNumber *m_person_active;

+ (id) Createperson;
- (id) init;
- (id) initWithUri:(NSString*)anUri;
@end

注意: 我尝试按照以下方式访问cellForRowAtIndexPath中的元素:

Entities *event = [items objectAtIndex:indexPath.row];
cell.textLabel.text = [[[event getperson] objectAtIndex: 0] getName];

并且它抛出一个错误,说“没有可见的@interface for'DataServiceQuery'声明选择器'ObjectAtIndex'”

更新:

getperson也在Entities.h中定义:

/**
* Container interface Entities, Namespace: Model
*/
@interface Entities : ObjectContext
{
 NSString *m_OData_etag;

    DataServiceQuery *m_member;

    DataServiceQuery *m_cumulative;

    DataServiceQuery *m_date;

    DataServiceQuery *m_holiday;

    DataServiceQuery *m_associations;

    DataServiceQuery *m_department;

    DataServiceQuery *m_person;

    DataServiceQuery *m_project;

}

@property ( nonatomic , retain , getter=getEtag , setter=setEtag : )NSString *m_OData_etag;

@property ( nonatomic , retain , getter=getmember , setter=setmember : ) DataServiceQuery *m_member;

@property ( nonatomic , retain , getter=getcumulative , setter=setcumulative : ) DataServiceQuery *m_cumulative;

@property ( nonatomic , retain , getter=getdate , setter=setdate : ) DataServiceQuery *m_date;

@property ( nonatomic , retain , getter=getholiday , setter=setholiday : ) DataServiceQuery *m_holiday;

@property ( nonatomic , retain , getter=getassociations , setter=setassociations : ) DataServiceQuery *m_associations;

@property ( nonatomic , retain , getter=getdepartment , setter=setdepartment : ) DataServiceQuery *m_department;

@property ( nonatomic , retain , getter=getperson , setter=setperson : ) DataServiceQuery *m_person;

@property ( nonatomic , retain , getter=getproject , setter=setproject : ) DataServiceQuery *m_project;

- (id) init;
- (id) initWithUri:(NSString*)anUri credential:(id)acredential;
- (id) member;
- (id) cumulative;
- (id) date;
- (id) holiday;
- (id) associations;
- (id) department;
- (id) person;
- (id) project;
- (void) addTomember:(id)anObject;
- (void) addTocumulative:(id)anObject;
- (void) addTodate:(id)anObject;
- (void) addToholiday:(id)anObject;
- (void) addToassociations:(id)anObject;
- (void) addTodepartment:(id)anObject;
- (void) addToperson:(id)anObject;
- (void) addToproject:(id)anObject;

@end

1 个答案:

答案 0 :(得分:1)

我认为你应该这样写:

Model_person* modelPerson = [items objectAtIndex:indexPath.row];
cell.textLabel.text = modelPerson.getperson_firstname;

而不是

Entities *event = [items objectAtIndex:indexPath.row];
cell.textLabel.text = [[[event getperson] objectAtIndex: 0] getName];