简体   繁体   English

如何在包含xml数据的UILabel的UItableview单元格中显示UIlabel?

[英]how can i display UIlabel in UItableview cell where UILabel containing the xml data?

this is my parser section where i am getting the attribute and values from the xml file.now when it will parse the xml concurrently should show the attribute and its value in the table view cell one bye one. 这是我的解析器部分,我从xml文件获取属性和值。现在何时将同时解析xml应该在表视图单元格中一一显示该属性及其值。

- (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;


} 

below my tableview where i want to show the xml data. 在我要显示xml数据的tableview下面。

- (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**

now i think you have got my question. 现在我想你有我的问题。

    - (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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果没有collectionview项目,如何在单元格中显示UILabel“未找到结果”? - How can I display UILabel “No result found” in cell if no collectionview item? 如何使UILabel从自定义单元格显示UITableView中保存的更改 - How to make UILabel from custom cell display saved changes in UITableView 如何在UILabel中显示XML解析的数据 - How to display XML parsed data in UILabel 如何在 UITableView 单元格中动态调整 UILabel 的大小? - How to dynamically resize UILabel in a UITableView Cell? 如果我从可重用单元格的超级视图中删除UILabel,那么在重用时如何在单元格中重新初始化UILabel? - If I remove a UILabel from superview in a Reusable cell, how can I reinitialise the UILabel in the cell when reusing? 如何在UILabel中显示html数据 - how to display html data in UILabel 如果UITableView没有数据,如何添加UIImage和UILabel - How to add UIImage and UILabel if UITableView has no data 如何在自定义表格视图单元格上获取UILabel? - How can I get UILabel on a custom table view cell? 如何在表格视图的单元格中更改UILabel的位置 - How can I change the position of UILabel within a cell of a tableview 如何将 UITapGestureRecognizer 添加到表视图单元格内的 UILabel? - How can I add a UITapGestureRecognizer to a UILabel inside a table view cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM