Professional Web Applications Themes

Converting string to NSDrawer pointer - Mac Programming

Hi, I'm trying to load a specific drawer from a NIB file, the NIB file containing many drawers. Basically I would like to use the function: -(void)openNib:(NSString *)nibName drawer:(NSString *)drawer onEdge:(NSRectEdge)edge; I have a problem in implementing that method. After having created and instantiated a drawer object in IB, called Drawer1, I don't know how to effectively access that object, since I only passed the name of the object as a string. What can I do to obtain the NSDrawer pointer to Drawer1 from the NSString, like I would use NSSelectorFromString to get a selector associated with a string ? ...

  1. #1

    Default Converting string to NSDrawer pointer

    Hi,
    I'm trying to load a specific drawer from a NIB file, the NIB file
    containing many drawers. Basically I would like to use the function:
    -(void)openNib:(NSString *)nibName drawer:(NSString *)drawer
    onEdge:(NSRectEdge)edge;

    I have a problem in implementing that method. After having created and
    instantiated a drawer object in IB, called Drawer1, I don't know how
    to effectively access that object, since I only passed the name of the
    object as a string. What can I do to obtain the NSDrawer pointer to
    Drawer1 from the NSString, like I would use NSSelectorFromString to
    get a selector associated with a string ?

    Here is the code:
    -(void)openNib:(NSString *)nibName drawer:(NSString *)drawerName
    onEdge:(NSRectEdge)edge
    {
    NSBundle *myBundle = [NSBundle loadNibNamed:nibName owner:self];

    // Here is what I'd like to have:
    NSDrawer *drawer= Pointer_from_NSString(drawerName);

    [drawer setParentWindow:[self mainWin]];
    [drawer openOnEdge:edge];
    }

    I am probably not understanding something fondamental. Thanks for your
    help,
    Maxime Curioni
    Maxime Guest

  2. #2

    Default Re: Converting string to NSDrawer pointer

    In article <google.com>, Maxime
    Curioni <com> wrote:
     

    Let's start with +loadNibNamed:owner: returns a BOOL, not an NSBundle.
     

    What you are missing is that you access the elements in NIB files
    through connections you make in IB. What you need to do here is in
    your controller (whatever class you are putting openNib in) you need to
    set IBOutlet's for each of your drawers. Your nib's File Owner needs
    to be set to be of the class for your controller and then you have to
    connect up these outlets. When the nib loads, the outlets will be
    filled in and you then can access them.

    Spence

    --
    James P. Spencer
    Rochester, MN

    "Badges?? We don't need no stinkin badges!"
    James Guest

  3. #3

    Default Re: Converting string to NSDrawer pointer

    com (Maxime Curioni) wrote:
     

    Sorry I wasn't precise enough. I am actually trying to get an IBOutlet
    NSDrawer pointer named Drawer1 from the string "Drawer1". In IB, I have
    linked File's Owner to the instantiated NSDrawer, with an outlet called
    Drawer1. So I would like to find a way to have access to that drawer.

    My code was wrong. It should be:

    -(void)openNib:(NSString *)nibName drawer:(NSString *)drawerName
    onEdge:(NSRectEdge)edge
    {
    [NSBundle loadNibNamed:nibName owner:self];

    // Here is what I'd like to have:
    IBOutlet NSDrawer *drawer= Outlet_from_NSString(drawerName);

    [drawer setParentWindow:[self mainWin]];
    [drawer openOnEdge:edge];
    }

    Thanks,
    Maxime
    Maxime Guest

  4. #4

    Default Re: Converting string to NSDrawer pointer

    In article <proxad.net>, Maxime
    Curioni <com> wrote:
     
     

    While I'm sure someone here has a better way, I would probably put the
    drawer's in an array and then instead of asking for the drawer by name,
    I'd ask for it by index but doing it the way you have it and assuming
    your outlets are declared:

    IBOutlet NSDrawer *firstDrawer;
    IBOutlet NSDrawer *secondDrawer;
    etc.

    - (NSDrawer *)Outlet_from_NSString:(NSString *)drawerName
    {
    if([drawerName isEqualToString:"NameOfFirstDrawer"])
    return firstDrawer;
    else if ([drawerName isEqualToString:"NameOfSecondDrawer"])
    return secondDrawer;
    else ...// etc

    else
    return nil;
    }

    Note that your variable in your method is not an outlet and you
    actually make the call:

    NSDrawer *drawer = [self Outlet_fromString:drawerName];

    Spence

    --
    James P. Spencer
    Rochester, MN

    "Badges?? We don't need no stinkin badges!"
    James Guest

  5. #5

    Default Re: Converting string to NSDrawer pointer

     

    Spence,
    Thanks for your answer. Sorry for the second message, I had written it
    before reading yours... Anyway, from reading your reply, I changed my
    way of doing things.
    I wanted to have the openNib:drawer:edge: function to avoid declaring
    all the outlets. Since I am using many nibs, each nib containing many
    drawers, I thought I could just pass the name of the drawer that would
    be opened, which would allow me to not declare all the outlets (I have
    about 35 potential drawers...). But I can't do that apparently; I went
    back to your solution of declaring all the outlets in the interface.
    Now I don't use openNib:drawer:edge but a openDrawer:edge: function.
    Because if I try to send it the pointer to the drawer, it passes nil
    since I must first load the nib, the pointer to the drawer being created
    at that moment.
    In conclusion, this solution works for me. I just thought that there was
    a way to access a pointer by its name, in the same way as
    NSSelectorFromString. Thanks,
    Maxime
    Maxime Guest

  6. #6

    Default Re: Converting string to NSDrawer pointer

    In article <proxad.net>,
    Maxime Curioni <com> wrote: 

    Look at Key-Value-Coding (KVC) stuff (such as valueForKey:) - it can
    get/set instance vars by name (which is the basis for how nibs work),
    Glenn Guest

Similar Threads

  1. Converting a String to number
    By Kaitlyn_k in forum Macromedia ColdFusion
    Replies: 2
    Last Post: May 3rd, 11:19 PM
  2. Converting a string to a movie command
    By Richard Atkins in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 24th, 08:19 PM
  3. Replies: 21
    Last Post: January 14th, 04:10 PM
  4. Converting a string to formatted html
    By Ian in forum PHP Development
    Replies: 2
    Last Post: October 27th, 11:13 AM
  5. mouse pointer not converting into hand
    By scholli webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 21st, 08:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139