English 中文(简体)
如何在含有xml数据的安全分析室展示质吗?
原标题:how can i display UIlabel in UItableview cell where UILabel containing the xml data?

这是我的教导部分,在这里,我正在从Xml档案中获取属性和价值。 现在,Xml将同时 par平时,表层的特性和价值就应逐字显示。

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 
//NSLog(@"found this element: %@", elementName); 
currentElement = [elementName copy]; 
if([elementName isEqualToString:@"ProductData"])
    {
    objectsArray = [[NSMutableArray alloc] init];
    productDict = [[NSMutableDictionary alloc] init];
   }

} 
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 
//NSLog(@"found characters: %@ %@", currentElement,string);
if(!currentString){
    currentString = [[NSMutableString alloc] init];
}
[currentString appendString:string]; 
} 
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:   (NSString *)namespaceURI qualifiedName:(NSString *)qName{ 
//NSLog(@"ended element: %@", elementName); 
if([elementName isEqualToString:@"id"])
{
    [productDict setObject:currentString forKey:@"id"];
    [self labelsetting:0];
    [currentString release],currentString = nil;

    return;
}
if([elementName isEqualToString:@"productNumber"])
{
    [productDict setObject:currentString forKey:@"productNumber"];
    [self labelsetting:0];
    [currentString release],currentString = nil;
    return;
}
if([elementName isEqualToString:@"name"])
{
    [productDict setObject:currentString forKey:@"name"];
    [self labelsetting:0];
    [currentString release],currentString = nil;
    return;
}
if([elementName isEqualToString:@"dateCreated"])
{
    [productDict setObject:currentString forKey:@"dateCreated"];
    [self labelsetting:0];
    [currentString release],currentString = nil;
    return;
}
if([elementName isEqualToString:@"image"])
{
    [productDict setObject:currentString forKey:@"image"];
    [self labelsetting:0];
    [currentString release],currentString = nil;
    return;
}
if([elementName isEqualToString:@"ProductData"])
{
    [objectsArray addObject:productDict];

    [productDict release],productDict = nil;
}
[currentString release], currentString = nil;


} 

下表是我想要显示xml数据的情况。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section    { 
return [objectsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
    //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];


}


productDict = [objectsArray objectAtIndex:indexPath.row];

NSString *data = nil;
for (NSString *key in [productDict allKeys] ) {
   // [data stringByAppendingFormat:@"%@ %@",key,[productDict objectForKey:key]];
    data = [NSString stringWithFormat:@"%@%@", key,[productDict objectForKey:key]];

    NSLog(@"data: %@",data);

}
cell.textLabel.text = data;

return cell;
[data release];
}

This the console of this view controller

2011-10-16 15:19:01.627 cmsCommander[1795:207] namestring: emon
2011-10-16 15:19:01.630 cmsCommander[1795:207] username: emon@test.com
2011-10-16 15:19:01.874 cmsCommander[1795:207] found file and started parsing
2011-10-16 15:19:01.877 cmsCommander[1795:207] current Element id : 1
2011-10-16 15:19:01.879 cmsCommander[1795:207] current Element productNumber :    a91cc0f4c7
2011-10-16 15:19:01.880 cmsCommander[1795:207] current Element name : Product 1
2011-10-16 15:19:01.881 cmsCommander[1795:207] current Element image :  5e928bbae358c93caedf6115fa7d178b.jpg
2011-10-16 15:19:01.882 cmsCommander[1795:207] current Element dateCreated : 2011-10-06T16:08:45
2011-10-16 15:19:01.883 cmsCommander[1795:207] current Element id : 2
2011-10-16 15:19:01.888 cmsCommander[1795:207] current Element productNumber : d8287e2e51
2011-10-16 15:19:01.892 cmsCommander[1795:207] current Element name : Product 2
2011-10-16 15:19:01.893 cmsCommander[1795:207] current Element image : 8bbd8dfff3cdd28285d07810a4fe7c32.jpg
2011-10-16 15:19:01.895 cmsCommander[1795:207] current Element dateCreated : 2011-10-06T16:08:45
2011-10-16 15:19:01.896 cmsCommander[1795:207] current Element id : 3
2011-10-16 15:19:01.897 cmsCommander[1795:207] current Element productNumber : 7931c08c22
2011-10-16 15:19:01.897 cmsCommander[1795:207] current Element name : Product 3
2011-10-16 15:19:01.902 cmsCommander[1795:207] current Element image : e19becad20d6f4378e37313c5dbdf070.jpg
2011-10-16 15:19:01.904 cmsCommander[1795:207] current Element dateCreated : 2011-10-06T16:08:45
2011-10-16 15:19:01.904 cmsCommander[1795:207] all done!
2011-10-16 15:19:01.906 cmsCommander[1795:207] The number of row in the object array:  1 
2011-10-16 15:19:01.909 cmsCommander[1795:207] data: name  Product 3
2011-10-16 15:19:01.910 cmsCommander[1795:207] data: id  3
2011-10-16 15:19:01.911 cmsCommander[1795:207] data: productNumber  7931c08c22
2011-10-16 15:19:01.912 cmsCommander[1795:207] data: image  e19becad20d6f4378e37313c5dbdf070.jpg
2011-10-16 15:19:01.913 cmsCommander[1795:207] data: **dateCreated  2011-10-06T16:08:45**

现在,我认为你已经提出问题。

最佳回答
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
            return 1;
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
            return [objectsArray count];
    }

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

            static NSString *CellIdentifier = @"Cell";

            UITableViewCell *currentCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

            if (currentCell == nil) {
                currentCell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
            }
            NSMutableDictionary *productDict = [objectsArray objectAtIndex:indexPath.row];
NSString *data = nil;
    for (NSString *key in [productDict allKeys] ) {
        [data stringByAppendingFormat:@"%@",key,[dic objectForKey:key]];
    }
            currentCell.textLabel.text = data;

            return currentCell;
    }
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签