I am a little lost as to where to put that last bit. Shouldn't it be a method in my Custom View class? If so, how the hell do I call it as I never instantiated the CustomView to begin with (it just works) so I have no idea where to send the message.

You could have the NSCustomView have an NSMutableArray of card objects. Then add addCard(CardThingy* card) and removeCard(CardThingy* card)

Then have the NSView draw the card list(s) every time and base their positions off of their index in the list.

Edit: By the way your going to want to pre-load all those images. The way you have it they will be loaded every time the game draws. Load them inside that if statement in the init method (I think), or in an awakeFromNib method. You could load all the images into an NSMutableDictionary, and give them keys like "table" and "clubs ace".

Then in your card class, instead of having an NSImage you could have a string like "clubs ace". When it draws it grabs the image with that key out of the dictionary.
(doesn't look like you have a card class though)

You could just make the keys cardName + " " + cardSuit. Its fine to have a reference to the Image in the card class, but make some kind of resource managing class that loads all the images and stores them with some access methods.

And I see you have an x and y stored in the card class, so thats handled.

I think what I need is some pointers as to how to redraw the table (with the new card on it) in response to an event. (button click.) In my app right now I can click a button and the card name of the next card object in the deck is sent to a text view. I am using this to test the stuff that I am writing. (I have been working with Xcode less than a month) I can draw the initial view of the table. But I am having trouble with how to draw the subsequent views with the new images. I guess the initial view loads automatically when the app runs. The problem is that I do not know the name of the View object so I can not write a method in it (like the one above for drawing the card) so that I can call it with:

Code:

[myView drawACard]

because I don't know the name of the "myView". With most objects I instantiate them myself with a name and then I can call their methods but I am really confused about this.

I suppose an easier question would be this: How would you draw anything (a static image for instance) into that view from a controller object?

hypnotx Wrote:I suppose an easier question would be this: How would you draw anything (a static image for instance) into that view from a controller object?

Seriously, the best way to tackle this is with a dataSource or delegate. Look how other NSTableView, NSOutlineView and other views handle this. They retrieve their data through methods that their dataSource implements.

Destin: I get what you are saying and that will be next. Right now, if I can just figure out how to change the content in the view by clicking a button in the UI I will be 90% there.

Stealth:

Code:

[myView setNeedsDisplay:YES]

That is what I would have expected. But myView is a class and not an object. I created it by subclassing NSView in Interface Builder and then dragging a custom view onto the window and setting the Custom Class in the Inspector to the subclass. After that when running the program it automatically draws anything in the custom class' drawRect method. I don't know the name of the instance to call the methods on. I never did:

Code:

myView * someView = [[myView alloc] init]

so I cant call setNeedsDisplay on it. Also, because I never created the instance that is being used when the program loads, I do not know how to call any of the methods that I would add to the subclass.

hypnotx Wrote:Destin: I get what you are saying and that will be next. Right now, if I can just figure out how to change the content in the view by clicking a button in the UI I will be 90% there.

Stealth:

Code:

[myView setNeedsDisplay:YES]

That is what I would have expected. But myView is a class and not an object. I created it by subclassing NSView in Interface Builder and then dragging a custom view onto the window and setting the Custom Class in the Inspector to the subclass. After that when running the program it automatically draws anything in the custom class' drawRect method. I don't know the name of the instance to call the methods on. I never did:

Code:

myView * someView = [[myView alloc] init]

so I cant call setNeedsDisplay on it. Also, because I never created the instance that is being used when the program loads, I do not know how to call any of the methods that I would add to the subclass.

Is this making any sense? I hope I am explaining it correctly.

So add an outlet to your controller and connect them. The easiest way to do this, I think, once the files have been already created is to add "IBOutlet MyView *theView;" to the header file, then drag the header file to the nib. Then you can control drag from the instance of your controller to the view and connect them.

Destin: BINGO! Thank you brother. That was what I needed to be able to move on. Still not comprehending some of the basics I guess. But I am getting there. Got some test code in there. Everything is cool but it draws my card on the button press then immediately erases it. I am sure I will be able to figure this one out though. Thanks again.