Radio buttons for a complete novice

At the risk of expecting far too much of this forum… my first post.

I’ve been trying to learn Xcode and Interface Builder and am about 120 pages into the “Cocoa Fundamentals Guide” and still have hardly any idea where to start. What I want to do seems relatively simple, but I can’t seem to find a tutorial or explanation of how to fundamentally structure an application. Specifically, and application with radio buttons. I’ve been able to connect radio buttons to a text field, but can only seem to get results of either, 1 or 0 and not the alternate text I’d like to. I thought of doing this with Applescript, but can’t find anything with radio buttons. The radio buttons aren’t really critical, but I figure I would try find out how to do something specific so as to not keep moving the goal posts. Those posts are not yet in view.

I’m trying to make a code that would rename project folders.

Ideally, what I’d like is a set of radio buttons for the first section so that my project codes stay consistent. Say for instance I have an art project and that code would be “ART.” What I would like to do is check a “Art Project” radio button would return “ART” for the first portion of the folder name all in caps, between two vertical slashes for visual separation, then have a “10” for the year followed by another vertical slash, then a “05” for the month of May, a dash and then a three digit number referring to the project numerator for that month, another vertical slash and finally, the project name. The end result would look like this: “| ART | 10 | 05-062 | Painting project for blah blah blah.” While it results in a fairly lengthy result, the vertical slash groups these project files together at the beginning or end of an alphabetized list, further organizes the files by the three letter project code, tells me the start date within a month, and an identifying number for that month, and finally a name. For extra credit, if possible I’d love for it to be able to search for other projects with the same start date (or actually month as defined in the folder name), disregarding the three digit project code and suggesting the next available number. More specifically, if I had begun twenty-six projects that month, it would do a search and suggest “027” as the next available number to be added after the months integer and the dash. While the actual code or application would be incredibly generous, I would be satisfied with a starting point or some reference that could guide a complete novice through what seems like an impossibility at this point.

Thanks in advance for any help you can offer. I’ll take whatever I can get!

Apple Power Mac G5 Dual 2.7GHz 16x SuperDrive (M9749LL/A), Mac OS X (10.6.3), It's silver and heats the room 12 degrees

Posted on May 21, 2010 10:14 AM

Reply
6 replies

May 21, 2010 4:11 PM in response to red_menace

As far as Xcode, I'm trying to learn Cocoa Objective-C. In Applescript, I'm just using the Applescript editor. Is the structure of Cocoa at all similar to Applescript (in that you define what the program is to expect beforehand) or is it a completely different animal? I understand the basic concept of actions (I think), but I'm not really understanding where the button name would reside as well as how to assign a series of letters for it's output. I'm going to look at the Button Programming Topics right now.

May 21, 2010 4:39 PM in response to Gavin Oglesby

Cocoa is the API, but it mostly uses Objective-C. Snow Leopard's AppleScriptObjC can call Cocoa methods, so depending on your particular needs (or knowledge), either one can be used for a simple user interface.

In your project you would create an Interface Builder action in your controller/delegate, e.g.
- (IBAction) myAction:(id) object {
# or
on myAction_(object)

then, from Interface Builder you can connect your user interface item to the action. From there, you can just do something like get the name of the button and build your file name accordingly. The other interface items would be set up in a similar fashion.

I can get the gist of Objective-C by reading it, but don't really know it well enough to write much using it, so I can just give you an example using ASOC.

May 26, 2010 8:24 AM in response to Gavin Oglesby

Gavin, if I understand your posts correctly I think you are expecting too much functionality from the radio button itself. Each radio button (technically, each radio button cell in an NSMatrix) simply indicates which option is selected and allows the user to change the selection by clicking on another cell. When this click occurs, the cell sends off its action method to its target. It is the target, most likely a 'controller' object, that does the actual work.

If you haven't got a handle on the Model-View-Controller pattern yet, have a look at the docs on it and it should give you some guidance on how to structure your application.

If I correctly understand what you want your application to do, I would suggest you structure your application like this:

Create a controller class (or use the application delegate class) and create 3 action methods for it:
-selectFolder:, -changeProjectType: and -setFolderName:, and create an IBOutlet for an NSMatrix instance variable

In Interface Builder, in your window, create a radio group (NSMatrix) with a cell for each of your project types (ART, etc). Connect this to your changeProjectType: method in your controller. You can also hook up buttons or menu items to trigger your selectFolder: and setFolderName: methods. Connect your controller NSMatrix outlet to your radio group.

The selectFolder: method you can use to display an NSOpenPanel to chose the folder you want to rename and store its location as a NSString path or an NSURL variable.

In your changeProjectType: method, you would carry out any tasks that need done are a result of changing the selected option, such as updating a textfield that shows a preview of the folder name. You can get the radio group's selected cell by calling NSMatrix's -selectedCell method on your outlet, and you can identify the cell with NSCell's -title or -tag methods.

The setFolderName: method would be where you actually rename the folder based on the options chosen with the radio buttons Again, you can query your outlet for the current selection. Look at NSWorkspace and NSFileManager for the actual renaming process.

Jun 1, 2010 9:06 AM in response to Jim McGowan

I really appreciate the your response. It was really helpful to see how this would or could be structured. I'm embarrassed that my questions seem so fundamental, but like I said before I'm a complete novice and trying to learn. That said, now that I've added these components in Interface Builder, is there a single file where these component designations have been added and would be connected to the controller(s) or are there multiple files that are accessed as needed by the program? I guess what I'm confused by is that I've been unable to find a complete project and have no real understanding of if there is a big master file that defines everything, an index file and an array of smaller, more specific files, of something else altogether. In other words, I feel as though everything I've read (excluding your post) has been very specific and not given much of an overview as to how everything works together or a start to finish tutorial. I'm wondering if merely being able to design the interface and making the rudimentary connections has given me a false confidence that I can do this. Designing the interface has been fun though.

Jun 1, 2010 8:53 PM in response to Gavin Oglesby

Normally your interface builder document (.xib file) 'glues' your interface elements to your code in XCode. Going back to the example I gave earlier, I'm going to assume/recommend you have created your UI in the 'MainMenu.xib' file and that you have added the IBOulets/IBActions to the ApplicationDelegate class. In Interface builder there will be an icon in your xib document window representing an instance of the ApplicationDelegate class. To connect the NSMatrix outlet to your radio button group, control-drag from the ApplicationDelegate icon to the radio group. Likewise to connect your buttons to the action methods in the ApplicationDelegate, control drag from each button to the ApplicationDelegate icon, and choose the desired action from the menu that pops up.

If you are unable to connect your outlets and actions this way, it is normally because they are not defined correctly in your .h file in XCode. And remember that you need to save this file after making changes for the changes to be picked up by Interface Builder.

For some basic tutorials that cover hooking up UIs with outlets and actions, have a look at the cocoadevcentral.com site.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Radio buttons for a complete novice

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.