Object Arrays (Equivalent of VB6 Load/Unload)

Discussion in 'Mac Programming' started by adimex, Feb 17, 2010.

  1. adimex macrumors newbie

    Joined:
    Feb 17, 2010
    #1
    Hello all,
    I am trying to do something like this in Cocoa:
    [​IMG]

    User clicks in the window and my Object (in this case, a UserControl with a drop pin appears where the user clicked). If the user clicks on the drop pin, another window will popup with information etc...

    How would I go about replicating a graphical object? Obj-C objects are piece of cake (UserControl *UC = [[UserControl alloc] init];...) but I can't seem to make it happen with graphical objects.

    VB Codes looks something like this:

    private sub form1_mouseDown(x as int, y as int)
    dim i as integer
    i = userControl.count

    load userControl(i)
    userControl(i).move x, y
    end sub

    thanks!!!
    D.
     
  2. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #2
    Well, technically, graphical objects *are* Objective-C objects, so you do the same thing, but there's more to displaying a graphical object than simply creating it.

    Code:
    	IBOutlet NSView * m_Output;
    
    ...
    
    	NSTextField * pOutput = nil;
    
    	NSRect frame = { { 0 } };
    	pOutput = [[NSTextField [COLOR="Blue"]alloc[/COLOR]] [COLOR="blue"]init[/COLOR]WithFrame: frame];
    			
    	if ( pOutput )
    	{
    		[pOutput setStringValue: @"A string"];
    		[pOutput autorelease];
    	}
    
    ...
    
    	[pOutput retain];
    	
    	[m_ParentView addSubview: pOutput];
    	[m_ParentView setAutoresizesSubviews: YES];
    	[pOutput setAutoresizingMask: ( NSViewWidthSizable | NSViewHeightSizable )];
    	
    	[m_ParentView setFrameSize: [m_ParentView frame].size ];
    	[m_ParentView setNeedsDisplay: YES];
    	[m_ParentView setNeedsDisplay: YES];
    
    ...
    
    That should give you an idea of a few things that might need to be done to make something visible.

    Of course, there's more to be done before it will be interactive as well.
     

Share This Page