0

I working on xml parsing.....

its parsed data success fully . i need to display title,date,time and picture.

it worked on title,date,time,

Now i need to display picture...

for picture its getting some url.....

aEventInfo.event_Picture=http://static.djguide.nl/image/flyers/2010/120/91426front.jpg

     NSURL *url3 = [NSURL URLWithString:aEventInfo.event_Picture];
        NSData *data = [NSData dataWithContentsOfURL:url3];
        NSLog(@"%@data",data);
        UIImage *imageView =[[UIImage alloc] initWithData:data];

            CGSize size;
            size.width=400;
            size.height=400;
            UIImage *scaledImage = [imageView scaleToSize:size];
            cell.imageView.image=scaledImage;

I did like this its crashing... if i got image url.

If aEventInfo.event_picture=nil. Its not crashing.

if any value in aEventInfo.event_picture .. example http://static.djguide.nl/image/flyers/2010/120/91426front.jpg My app get crashed.

I dont know how to do..

can any one advice me and help me out in this case.

@thanks in advance.

1
  • Use JonLOo method to create url with string Commented Dec 28, 2010 at 10:12

4 Answers 4

1

You should use the connection methods. for example, connectionDidReceive, ConnectionDidFinish. You should first create request and make a connection using connection Object. And after that writedown connection Methods.

Sign up to request clarification or add additional context in comments.

3 Comments

@Raxit...do you have any example for this connection methods.
you find the sample code over here developer.apple.com/library/ios/navigation/…. sample code like SimpleURLConnections,AdvancedURLConnections,URLCache. This is helpful.
@ Raxit thanks a lot its working for me. NSURL *url = [NSURL URLWithString:aEventInfo.event_Picture]; NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:nil error:nil]; imageView.image = [UIImage imageWithData:data];
0

aEventInfo.event_Picture is an NSString?? and you are initializing it properly? because the code to retrieve the image seems to be ok, your problem seems to be the string you are passing to get the URL.

It should be something like:

NSString* urlString= @"http://static.djguide.nl/image/flyers/2010/120/91426front.jpg";

and then NSURL *url3 = [NSURL URLWithString:urlString];

4 Comments

yeap Its a string.NSString. and it initialized properly, while parsing. i get aEventInfo.event_Picture. value so that means my initializing done perfectly.
can you post the crash here? and the way you are parsing aEventInfo.event_Picture
-[UIImage length]: unrecognized selector sent to instance 0x736f840 2010-12-28 16:00:18.052 PartyTemperature [715:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x736f840' *** Call stack at first throw:
this is telling you that you are trying to call length method which is an NSString method in an UIImage instance, so it seems you are initializing an string as an UIImage somewhere
0

I respect Open..source

This is my code.... //Parsing class.....

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict{

    if ([elementName isEqualToString:@"events"]) {
        appDelegate.eventListArray=[[NSMutableArray alloc]init];
}
    if ([elementName isEqualToString:@"event"]) {
//      NSString * stringValue = [attributeDict objectForKey:@"id"];
//      [appDelegate.eventListArray addObject:stringValue];
        aEventInfo=[[EventInfo alloc]init];

        aEventInfo.event_ID=[attributeDict objectForKey:@"id"];
        aEventInfo.event_Title=[attributeDict objectForKey:@"title"];
        aEventInfo.event_Description=[attributeDict objectForKey:@"description"];
        aEventInfo.event_Date=[attributeDict objectForKey:@"date"];
        aEventInfo.event_Time=[attributeDict objectForKey:@"time"];
        aEventInfo.event_Location=[attributeDict objectForKey:@"location"];
        aEventInfo.event_Street=[attributeDict objectForKey:@"street"];
        aEventInfo.event_City=[attributeDict objectForKey:@"city"];
        aEventInfo.event_Visitors=[attributeDict objectForKey:@"visitors"];
        aEventInfo.event_Organisation=[attributeDict objectForKey:@"organisation"];
        aEventInfo.event_Price=[attributeDict objectForKey:@"price"];
        aEventInfo.event_Minimum_Age=[attributeDict objectForKey:@"minimum_age"];
        aEventInfo.event_Picture=[attributeDict objectForKey:@"picture"];
        aEventInfo.event_Genre=[attributeDict objectForKey:@"genre"];
        aEventInfo.event_LineUP=[attributeDict objectForKey:@"lineup"];
        aEventInfo.event_WebSite=[attributeDict objectForKey:@"website"];

    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
    if ([elementName isEqualToString:@"events"]) {
        NSLog(@"Value of appDelegate is %@",appDelegate.eventListArray);

    }
    if ([elementName isEqualToString:@"event"]) {

        [appDelegate.eventListArray addObject:aEventInfo];
        NSLog(@"appDelegate.eventListArray count %d",[appDelegate.eventListArray count]);
    }
}

//Displaying Data.... in my tableview. from controller class. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
//    return [categorieArray count];
    return [appDelegate.eventListArray count];

}

    // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle= UITableViewCellSelectionStyleBlue;
        cell.backgroundColor=[UIColor blueColor];
        cell.textLabel.textColor=[UIColor redColor];
        cell.detailTextLabel.textColor=[UIColor blackColor];
        cell.detailTextLabel.font=[UIFont systemFontOfSize:10];
    }
    aEventInfo=[[EventInfo alloc] init];
    aEventInfo=[appDelegate.eventListArray objectAtIndex:indexPath.row];
    cell.textLabel.text=aEventInfo.event_Title;
    cell.detailTextLabel.text=[NSString stringWithFormat:@"City: %@\n Date: %@          Time: %@",[aEventInfo event_City],[aEventInfo event_Date],[aEventInfo event_Time]];



    NSURL *url3 = [NSURL URLWithString:aEventInfo.event_Picture];
    NSData *data = [NSData dataWithContentsOfURL:url3];
    NSLog(@"%@data",data);
    UIImage *imageView =[[UIImage alloc] initWithData:data];

    CGSize size;
    size.width=400;
    size.height=400;
    cell.imageView.image=[UIImage imageNamed:imageView];
    return cell;

}

//EventInfo class

@interface EventInfo : NSObject {
    NSString *event_ID;
    NSString *event_Title;
    NSString *event_Description;
    NSString *event_Date;
    NSString *event_Time;
    NSString *event_Location;
    NSString *event_Street;
    NSString *event_City;
    NSString *event_Visitors;
    NSString *event_Organisation;
    NSString *event_Minimum_Age;
    NSString *event_Price;
    NSString *event_Picture;
    NSString *event_Genre;
    NSString *event_LineUP;
    NSString *event_WebSite;
}
@property (nonatomic,retain)NSString *event_ID;
@property (nonatomic,retain)NSString *event_Title;
@property (nonatomic,retain)NSString *event_Description;
@property (nonatomic,retain)NSString *event_Date;
@property (nonatomic,retain)NSString *event_Time;
@property (nonatomic,retain)NSString *event_Location;
@property (nonatomic,retain)NSString *event_Street;
@property (nonatomic,retain)NSString *event_City;
@property (nonatomic,retain)NSString *event_Visitors;
@property (nonatomic,retain)NSString *event_Organisation;
@property (nonatomic,retain)NSString *event_Minimum_Age;
@property (nonatomic,retain)NSString *event_Price;
@property (nonatomic,retain)NSString *event_Picture;
@property (nonatomic,retain)NSString *event_Genre;
@property (nonatomic,retain)NSString *event_LineUP;
@property (nonatomic,retain)NSString *event_WebSite;

@end

5 Comments

and i @synthesize every object in my EventInfo. class
try to make a cast before the eventInf.event_picture: NSURL *url3 = [NSURL URLWithString:(NSString *)aEventInfo.event_Picture];
can you try to introduce the string like i told you before without parsing just to test if its retrieving the data properly? NSString* urlString= @"static.djguide.nl/image/flyers/2010/120/91426front.jpg";
I try this code...NSString *urlimage=@"static.djguide.nl/image/flyers/2010/120/90511front.jpg"; NSURL *url3 = [NSURL URLWithString:urlimage]; NSData *data = [NSData dataWithContentsOfURL:url3]; NSLog(@"%@data",data); UIImage *imageView =[[UIImage alloc] initWithData:data]; CGSize size; size.width=400; size.height=400; UIImage *scaledImage = [imageView scaleToSize:size]; cell.imageView.image=scaledImage; return cell; ...IT just displaying data not image
why are you creating a new UIIMage? try using cell.imageView.image= [imageView scaleToSize:size];
0

Have you tried using TouchXML. XML parsing becomes very easy to use with TouchXML. I was facing the same problem using NSXMLParser. Switched over to TouchXML, and XML parsing became easier.

Check this link

2 Comments

. I am using NSXMLParser... i get learn parsing new to iphone
Just try using TouchXML. Its very easy to use. You just have to follow the steps provided in the link. Even iam in beginner stage of iPhone programming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.