Can someon help me please with Xcode and Interface Builder?

Discussion in 'Mac Programming' started by markhtfc, Jan 30, 2007.

  1. macrumors newbie

    #1
    Hey,

    Well let me start of by saying this is my first post and my name is Mark and I am 17 years old. Now how I came about programming? Well I wanted to do it when I was younger but never really took it up, I am in my second year at college and we are currently doing C++ and HTML. Since doing programming at college it has really got me wanting to do programming as a proffesion. I am really advanced in C++ (compared to other students)though as the teacher would like to set me some more challenging tasks. So maybe I have a brain for programming heh.

    Well onto the purpose of my post. I have not had a Mac that long. Not long before Christmas. I am looking at creating a Managing Game, I am using Xcode and Interface Builder. At the moment before I make the whole background and everything first I want to try and understand how to make action buttons work. (if I knew how to provide screenshots from a Mac I would do so you can understand easier). Well anyway what I have got so far is a title, Start New game button and a Quit button. I also have a screen that I want my New Game button to connect to.

    The question I have is how do I get my new game button to go to that screen? and how do I get my Quit button to quit the program? I have tried a few times but had no luck.

    I hope that someone will be able to help me as I would really be able to make a game, I would love to be a programmer. I am looking at going to uni to do a course maybe but I don't want it to turn out as a lost cause. As I have known a few people who has had to move away to do work in that area.

    Thank your for listening and I hope you can help.

    Thank you

    Mark
     
  2. Moderator

    robbieduncan

    Staff Member

    #2
    Are you using Carbon or Cocoa? I assume Carbon as you are talking about C++ but without knowing we can't really help you (and if it's Carbon I can't help you)...
     
  3. macrumors newbie

    #3
    Sorry about that. I am using Cocoa as that is what I was reccomended to use.
     
  4. macrumors 603

    gauchogolfer

    #4
    I'm no programmer, but I can help with the taking screenshots part. Here's a summary.
     
  5. Moderator

    robbieduncan

    Staff Member

    #5
    OK great. Cocoa is easy. But we need to agree on the normal terminology... What is this "screen"? Is it an NSWindow? An NSView? Something else?

    Have you read up at all in the documentation on how the action messages get passed down the responder chain?

    The simplest way to get this to work is to create a new object to use as the controller, instansiate that in IB and create the actions in there to deal with the windows.
     
  6. macrumors newbie

    #6
  7. macrumors 65816

    Lovesong

    #7
    One thing to remember is that programming in Cocoa uses Objective-C, and not C or C++. Is that what you're writing in?
     
  8. macrumors newbie

    #8
    yeah I am using Objective C. I am using C++ at college, I gatherd with it being on a Mac it would be a different code to Windows.
     
  9. Moderator

    robbieduncan

    Staff Member

    #9
    Ok. There is no such thing as a screen. That's a Window. Do you want to allow multiple games at once or not? If the answer is yes then you need to use a Document Based app, otherwise not.

    If the answer is a single game at once then why not just have the window appear on startup?
     
  10. Moderator

    robbieduncan

    Staff Member

    #10
    Ok I see what you are trying to do. But why? This is not anything like a Mac user interface. You should not have a Quit button. Or a new game button like that. You need to use the actual menus.
     
  11. macrumors newbie

    #11
    Sorry about that, I should explain with the proper terminology. Sorry again.

    About the multiple games not really know, As this is my first attempt.

    I don't quite understand your last question, I would like a main menu so I can then move onto the Create manager Screen and so on.
     
  12. Moderator

    robbieduncan

    Staff Member

    #12
    My point is that's not a menu. A menu is the thing at the top of the screen. It has a pre-populated perfectly functioning quit item. I understand a welcome view within the main window though. Give me 15 minutes: I'm knocking up a demo project...
     
  13. macrumors newbie

    #13
    I am not generally looking for a Mac user interface right at this minute. I am mainly looking at how I can make them do actions as I would like them to do seen as this is my first attempt.
     
  14. macrumors newbie

    #14
    Ok thank you. like I say programming is all new to me, The Mac is still new also. I am hoping to do programming though at a decent level so if I do go to Uni I will know what i am doing. Plus I find it very intresting and a great hobbie.
     
  15. Moderator

    robbieduncan

    Staff Member

    #15
    So attached is an XCode project to demonstrate one of the possible ways of doing this. What we have is a single window that contains a NSTabView. This currently has 2 tabs one for each "screen" you want to display. The tabs themselves are hidden.

    There is also an NSObject subclass that is our "controller" object. It has the action code in it to start the game. When the button is pressed this is called. All it does is select the next tab.

    If this is all greek to you then you need to buy a book, or at the very least run through the guided, step by step demos on the Apple site that will take you through the basic design patterns you need to know, primarily MVC and how to connect the outlets and actions of objects in IB.
     

    Attached Files:

  16. macrumors newbie

    #16
    Ok thank you for that. So by what you are saying what I am trying to do I can't actually do it?

    I will have a look at the step by step guides tomorrow as I will have more time then.

    Thank you for your help and producing the Demo for me. :)
     
  17. Moderator

    robbieduncan

    Staff Member

    #17
    No the demo does what you want to do (apart from the Quit button but that's really easy). I'm suggesting that you will need read up on the documentation to get anywhere.
     
  18. Moderator emeritus

    kainjow

    #18
    What about NSScreen? :confused:

    :p ;)
     
  19. Moderator

    robbieduncan

    Staff Member

    #19
    Yes OK, as in a whole screen, but not as in a view displayed in a window!

    And :p :p to you too!

    I'm just glad the OP hasn't been asking about going full screen for the game yet as that's a pain...
     
  20. macrumors 6502

    #20
    I'll just mention that the MacDevCenter articles (especially the early ones) are quite good for Cocoa beginners in that they go through how to link buttons in IB to your code, IIRC. It's a fairly simple concept once you get it, but it is necessary before anything will actually work!

    http://www.macdevcenter.com/pub/ct/37
     
  21. macrumors 6502a

    #21
    Not true, you can mix Objective-C and C++, just give your source files a .cpp extension. This will run them through the Objective-C++ compiler. I do this all the time as I much prefer C++ to Objective-C, but prefer to use Cocoa than Carbon.

    b e n
     
  22. macrumors newbie

    #22
    Thanks for your help everyone.

    Thank you for the link Cazlar, I had a look at that this morning and I read the first article. It looks intrsesting. Going to go through each article to see if it will help me out more.
    Mark
     

Share This Page