开发者

trying to write data into an array after parsing and then filling my cell.textlabel.text with array daya

开发者 https://www.devze.com 2023-04-02 06:04 出处:网络
in my project i am having a xml in my resource folder.I want to read values from xml into my tableview cell.for this i am having a mutable array.my code upto this is as:

in my project i am having a xml in my resource folder.I want to read values from xml into my tableview cell.for this i am having a mutable array.my code upto this is as:

<?xml version="1.0" encoding="UTF-8"?>

<rowstype1>


    <row>
        <user>olga</user>
        <score>45000</score>
    </row>
    <row>
        <user>alok</user>
        <score>23000</score>
    </row>

i am having a data structure class as: Row.h and Row.m as below:

#import "Row.h"


@interface Row: NSObject
{
    NSString *user;  
    NSString *score;  
    NSString *roll;
}

@property (nonatomic, retain) NSString *user; 
@property (nonatomic, retain) NSString *score; 
@property (nonatomic, retain) NSString *roll; 
@end 

My xmlparser.h and xml parser.m i am putting only significant part here:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

if ([elementName isEqualToString:kName_response]) {

}else if ([elementName isEqualToString:kName_responseCode]) {
    self.responseCode=[[NSString alloc] initWithString: currentString];
}else if ([elementName isEqualToString:kName_rows]) {

}else if ([elementName isEqualToString:kName_row]) {
    Row *row  = [[Row alloc] init];
    row.user=self.user;
    row.score=self.score;
    row.roll=self.roll;
    [self.rows insertObject:row atIndex:index];
    index=index+1;
    [row release];

}else if ([elementName isEqualToString:kName_user]) {
    self.user=[[NSString alloc] initWithString: currentString];
}else if ([elementName isEqualToString:kName_score]) {
    self.score=[[NSString alloc] initWithString: currentString];
}else if ([elementName isEqualToString:kName_roll]) {
    self.roll=[[NSString alloc] initWithString: currentString];
}

storingCharacters = NO;

}

now i am trying to access this array named rows(a nsmutable array) in my tableview controller. i am not able to fill my cell.textlabel.text with user(see on top xml structure ie; olga then alok then so on).

if am able to have all the value in console with this line of code:(row and parser are the instance variable of class Row an XmlParser)

for (row in parser.rows) {
    NSLog(@"ROW user=%@ score =%@", row.user,row.score);}

when i try to access the mutable array rows in cellforrowatindexpath i get only first value:olga, code is as:

row=[parser.rows objectAtIndex:indexPath.row];
cell.textLabel.text=row.user;
return cell;

i am getting indexpath.row as 0 and row.user开发者_高级运维 as the 0th element of the array..how to access all the elements..what i am doing wrong??any suggestion? nslog is as:

2011-09-02 18:01:46.113 mytableviewcontroller[3862:40b] indexPath.row value is (null) :

2011-09-02 18:01:46.114 mytableviewcontroller[3862:40b] parser.rows value is ( "Row: 0x4b55110", "Row: 0x4b5ea50", "Row: 0x4b5ea40", "Row: 0x4b5eb10", "Row: 0x4b5ebd0", "Row: 0x4b5ed60", "Row: 0x4b5ee80", "Row: 0x4b5ef50", "Row: 0x4b5ef40", "Row: 0x4b5f0f0", "Row: 0x4b5ec90", "Row: 0x4b5f1b0" ) : 2011-09-02 18:01:46.115 mytableviewcontroller[3862:40b] row.user value is olga :

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号