PrepareForSegue on iPad

Discussion in 'iOS Programming' started by nashyo, May 11, 2012.

  1. nashyo, May 11, 2012
    Last edited by a moderator: May 11, 2012

    nashyo macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    The following method has no warnings or errors associated with it in Xcode.

    Code:
    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        ChecklistsViewController *clvc = [segue destinationViewController];
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        clvc.htmlString = [array2 objectAtIndex:indexPath.row];
    }
    I receive the following message at runTime.

    Code:
    "'NSInvalidArgumentException', reason: '-[ChecklistsViewController setHtmlString:]: unrecognised"
    I am developing for iPad so these controllers have been 'targeted for iPad' if that makes any difference.

    Why is setHtmlString unrecognised? It is set as a public NSString property in the destinationViewController.

    The destinationViewController is not embedded in a navigation controller.
     
  2. Ron C macrumors member

    Joined:
    Jul 18, 2008
    Location:
    Chicago-area
    #2
    First, you didn't provide the entire error message. I suspect that it says that it's an unrecognized selector on the object that is actually pointed at by the segue (segue.destinationViewController) - maybe a UIViewController or UITableViewController object. Stop in the debugger and determine exactly what the object is that gets stored in your clvc variable.

    If that is the case, it means that the view controller that the segue points at is not a ChecklistsViewController. Double check that and get back to us.
     
  3. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #3
    Full error message

    2012-05-12 09:05:19.881 readHTML[379:f803] -[ChecklistsViewController setHtmlString:]: unrecognized selector sent to instance 0x6d7e780
    2012-05-12 09:05:19.893 readHTML[379:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChecklistsViewController setHtmlString:]: unrecognized selector sent to instance 0x6d7e780'
    *** First throw call stack:
    (0x13c9022 0x155acd6 0x13cacbd 0x132fed0 0x132fcb2 0x2c04 0x43e4be 0xa4581 0xa47fa 0x93985d 0x139d936 0x139d3d7 0x1300790 0x12ffd84 0x12ffc9b 0x12b27d8 0x12b288a 0x13626 0x247d 0x23e5)
    terminate called throwing an exception(lldb)

    ----------

    array2 contains strings only. the htmlString variable is a string property.

    there are no warnings or errors in Xcode at compile time (before run time).
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Obviously, you're trying to call the method on ChecklistsViewController called setHtmlString.
    Tada, rocket science debugging.
    Obviously somewhere, on a button or whatever you have that code (i didn't read through all the code), so therefore your code is failing hard.
     
  5. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    You probably got a warning about this. Don't ignore those.
     
  7. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
  8. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #8
    Not trying to hijack the post but in all my segues I use segue.destinationViewController instead of [segue destinationViewController]

    Is there a big problem with this?
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    No, the former is just a syntactic shortcut for the latter.
     
  10. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #10
    That's what I thought. Thanks
     
  11. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #11
    Brackets-syntax is called Objective C 1.1, using the DOT syntax is actually Objective C 2.0.
    Allthough I've had some issues with mixing them which caused alot of confusion, i believe the dot syntax is mostly used for lets say setting properties etc.
    Square brackets are ofcourse needed to call Methods on classes/objects.
     
  12. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #12
    Right, which is why I use segue.destinationViewController. To me that reminds me that the destinationVC is a property of the segue (maybe, I am kinda new to this stuff) whereas when I call [self performSegue...] it is a method on the self object
     

Share This Page