2011-10-11 2 views
0

아무도 도와주세요. 나는 UItableView로 특정 속성과 XML 데이터의 값을 표시하려고합니다. 하지만 난 어떻게 할 수 있을지 모르겠다. 나는 XML 데이터를 구문 분석 할 수있는 아무 문제가 있고 이미 콘솔에서 해본 적이 있지만 UITableview 또는 UIView에서 특정 특성 이름과 값을 사용하여 이러한 데이터를 표시 할 수 없게되고있다.xml 데이터를 구문 분석하여 UITableview에 표시하십시오.

` 
<list> 
<ProductData HASH="1892201664"> 
<id>1</id> 
<productNumber>a91cc0f4c7</productNumber> 
<name>Product 1</name> 
<seoTitle>product-1</seoTitle> 
<viewCount>0</viewCount> 
<availableStock>100.0</availableStock> 
<lowStock>0.0</lowStock> 
<image>5e928bbae358c93caedf6115fa7d178b.jpg</image> 
<basePrice>10.0</basePrice> 
<costPrice>0.0</costPrice> 
<height>1.0</height> 
<width>1.0</width> 
<depth>1.0</depth> 
<weight>2.0</weight> 
<status>A</status> 
<quantityOrderMin>1.0</quantityOrderMin> 
<productIsCall>false</productIsCall> 
<quantityOrderMax>20.0</quantityOrderMax> 
<orderCount>0</orderCount> 
<sortOrder>1</sortOrder> 
<isFreeShipping>false</isFreeShipping> 
<productIsFree>false</productIsFree> 
<isDeleted>false</isDeleted> 
<priceByAttribute>false</priceByAttribute> 
<dateCreated>2011-10-06T16:08:45</dateCreated> 
<dateUpdated>2011-10-06T10:08:45</dateUpdated> 
<isDummy>true</isDummy> 
<isInventory>false</isInventory> 
</ProductData>` 

줘요 소스 코드를 보내 주시기 바랍니다 수있는 사람에게 문제 심각한에서 오전 도와주세요 ... 여기 내 XML 데이터입니다 ... XML에서 속성.

미리 감사드립니다.

답변

1
#pragma mark tableview 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

int sectionCount = [records count]; 
NSLog(@"section cout: %d",sectionCount); 
return sectionCount; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *MyIdentifier = @"MyIdentifier"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; 
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]]; 
    cell.accessoryView = imageView; 
    cell.accessoryType = UITableViewCellSelectionStyleNone; 
    tableView.separatorColor = [UIColor clearColor]; 
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 

    cellView = [[[UIView alloc] initWithFrame:CGRectMake(5,8,290, 120)] autorelease]; 
    cellView.backgroundColor = [UIColor clearColor]; 
    cellView.tag =10; 
    [cell.contentView addSubview:cellView]; 

    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 40, 48, 48)]; 
    imgView.image = [UIImage imageNamed:@"productbox.png"]; 
    imgView.layer.borderColor = [UIColor blackColor].CGColor; 
    imgView.layer.borderWidth = 2.0; 
    imgView.tag = 5; 
    [cellView addSubview:imgView]; 

    CGRect idLabelRect = CGRectMake(65, 0, 190, 18); 
    idLabel = [[[UILabel alloc] initWithFrame:idLabelRect] autorelease]; 
    idLabel.textAlignment = UITextAlignmentLeft; 
    idLabel.textColor = [UIColor blackColor]; 
    idLabel.font = [UIFont systemFontOfSize:12]; 
    idLabel.backgroundColor = [UIColor clearColor]; 
    idLabel.layer.borderColor = [UIColor grayColor].CGColor; 
    idLabel.tag = 0; 

    CGRect statusRect = CGRectMake(65, 22, 190, 22); 
    statusLabel = [[[UILabel alloc] initWithFrame:statusRect] autorelease]; 
    statusLabel.textAlignment = UITextAlignmentLeft; 
    statusLabel.textColor = [UIColor blackColor]; 
    statusLabel.font = [UIFont systemFontOfSize:12]; 
    statusLabel.backgroundColor = [UIColor clearColor]; 
    statusLabel.layer.borderColor = [UIColor grayColor].CGColor; 
    statusLabel.tag = 1; 

    CGRect orderDateRect = CGRectMake(65, 48, 190, 22); 
    orderDate = [[[UILabel alloc] initWithFrame:orderDateRect] autorelease]; 
    orderDate.textAlignment = UITextAlignmentLeft; 
    orderDate.textColor = [UIColor blackColor]; 
    orderDate.font = [UIFont systemFontOfSize:12]; 
    orderDate.backgroundColor = [UIColor clearColor]; 
    orderDate.layer.borderColor = [UIColor grayColor].CGColor; 
    orderDate.tag = 2; 

    CGRect byRect = CGRectMake(65, 75, 190, 22); 
    byLabel = [[[UILabel alloc] initWithFrame:byRect] autorelease]; 
    byLabel.textAlignment = UITextAlignmentLeft; 
    byLabel.textColor = [UIColor blackColor]; 
    byLabel.font = [UIFont systemFontOfSize:12]; 
    byLabel.backgroundColor = [UIColor clearColor]; 
    byLabel.layer.borderColor = [UIColor grayColor].CGColor; 
    byLabel.tag = 3; 

    CGRect totalRect = CGRectMake(65, 98, 190, 22); 
    totalLabel = [[[UILabel alloc] initWithFrame:totalRect] autorelease]; 
    totalLabel.textAlignment = UITextAlignmentLeft; 
    totalLabel.textColor = [UIColor blackColor]; 
    totalLabel.font = [UIFont systemFontOfSize:12]; 
    totalLabel.backgroundColor = [UIColor clearColor]; 
    totalLabel.layer.borderColor = [UIColor grayColor].CGColor; 
    totalLabel.tag = 4; 

    [cellView addSubview:idLabel]; 
    [cellView addSubview:statusLabel]; 
    [cellView addSubview:orderDate]; 
    [cellView addSubview:byLabel]; 
    [cellView addSubview:totalLabel]; 
} 

//for removing overlapping problem 

cellView = (UIView *)[cell.contentView viewWithTag:10]; 
idLabel = (UILabel *)[cellView viewWithTag:0]; 
statusLabel = (UILabel *)[cellView viewWithTag:1]; 
orderDate = (UILabel *)[cellView viewWithTag:2]; 
byLabel = (UILabel *)[cellView viewWithTag:3]; 
totalLabel = (UILabel *)[cellView viewWithTag:4]; 
imgView = (UIImageView *)[cellView viewWithTag:5]; 


    //records is an mutable array which also containing a nsarray. 

idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:0]]; 
statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:1]]; 
orderDate.text = [NSString stringWithFormat:@"Date: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:2]]; 
byLabel.text =[NSString stringWithFormat:@"By: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:3]]; 
totalLabel.text =[NSString stringWithFormat:@"Total: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:4]]; 

return cell; 
} 
관련 문제