Using the NSXMLParser i can retrieve the data from the local XML file, but the image path i had given in the XML file is not retrieving. The code below shows you in detail.
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Prices.xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
egsParser *theParser =[[egsParser alloc] initParser];
[xmlParser setDelegate:theParser];
From this code i can parse the data but don't know how to retrieve the image along with this and show it in table view. The table view code is as below.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
theLists = [app.listArray objectAtIndex:indexPath.row];
cell.textLabel.text = theLists.title;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Kindly suggest an idea to parse and show the image in table view from local XML file
Use the following code
cell.imageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"Your Image Link"]]];
or
cell.imageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSString stringWithFormat:@"Your Image Link"]]];
as per your code it will be like below.
cell.imageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theList.imgUrl]]];
if you want to Retrive image from Saved Path
cell.imageView.image= = [UIImage imageWithContentsOfFile:@"yourSavedpath"];
You have to use delegate methods to parse the XML file...
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
}
By using these delegate methods you get the your required element.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.