Problem with NSStrings

Discussion in 'iOS Programming' started by alexandergre, Sep 11, 2009.

  1. alexandergre macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #1
    This code works correctly. It loads the google.com in UIWebVIew.
    Code:
    		NSLog(aBook.title);  //output is :Yahoo
    		NSLog(aBook.author); //output is : http://www.yahoo.com
    			
    		NSString *path = [[B]NSString stringWithFormat:@"http://www.google.com"[/B]];
    		NSURL *url = [NSURL URLWithString:path];
    		NSURLRequest *request = [NSURLRequest requestWithURL:url];
    		[myWebView loadRequest:request];
    

    But not this one. How can I fix this. I dont understand.
    Code:
    		NSLog(aBook.title);  //output is :Yahoo
    		NSLog(aBook.author); //output is : http://www.yahoo.com
    			
    		NSString *path = [[B]NSString stringWithFormat:@"%@",aBook.author[/B]];
    		NSURL *url = [NSURL URLWithString:path];
    		NSURLRequest *request = [NSURLRequest requestWithURL:url];
    		[myWebView loadRequest:request];
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    What exactly is not working? Are you getting any run-time errors?
     
  3. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #3
    sorry if I reply so late. Been away.
    The URL wont load in the UIwebview.
    NO run time errors. If you want I can upload the project. Its really strange.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Might as well. My code test loads Yahoo just fine.
     
  5. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #5
    http://eskapps.com/XML.zip
    the code is in: BookDetailViewController.m
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Thanks. I'll look into it.

    Before I do that though, here's a suggestion: the proper way to use NSLog
    Code:
    NSLog(@"%@", aBook.title);  //output is :Yahoo
    NSLog(@"%@", aBook.author); //output is : http://www.yahoo.com
    
     
  7. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #7
    Thank you man.
    I really appreciate it. :p
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Here's your problem:
    aBook.author doesn't contain "http://www.yahoo.com". It contains "/nhttp:www.yahoo.com".

    How did I figure this out? Simple. I put a breakpoint at the line that assigns path and used the Debugger window to tell me what path was getting assigned. So, the lesson is: use breakpoints and use the Debugger!
     
  9. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #9
    WOW man that was quick.
    Thank you very very much. YOu are great. How long have been a iphone developer? other langs?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Been an iPhone developer since July 2008. Other languages? How much time you got? ;) I'll give you the major ones, starting with programming the Commodore PET in 1981: BASIC, 6502 Assembler, C, Nomad, PL/SQL, Java.
     

Share This Page