0

我是 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);

这很好用并打印以下内容:

在此处输入图像描述

但是,我不知道如何访问 Model_person 中的变量。

Entity.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];

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

更新:

getperson 也在 Entity.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
4

1 回答 1

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];
于 2013-07-10T17:58:59.540 回答