Is there something similar to JOptionPane in Objective-C? - objective-c

I'm trying to create a simple game in Objective-C. In Java I could use JOptionPane.showMessageDialog to create a simple window with a message or JOPtionPane.showInputDialog to create a simple input window... Is there's something similar in Objective-C? (Or Cocoa, or whatever I could use...)

I'm not familiar with JOptionPane, but you can use UIAlertView to do both of those things. By default, it displays a message with either one or two buttons. As of iOS 5, it also has style properties to give it a UITextField, which would make a simple input prompt.

Related

Don't Understand Apple's takeFloatValueFrom: Example

I'm no iOS guru but I know enough to build apps. I know and understand the patterns, UIKit, and Objective-C. I'm now learning Mac Development and this little bit of "Cocoa Bindings Programming Topics" has me stumped:
Take as an example a very simple application in which the values in a text field and a slider are kept synchronized. Consider first an implementation that does not use bindings. The text field and slider are connected directly to each other using target-action, where each is the other’s target and the action is takeFloatValueFrom: as shown in Figure 2. (If you do not understand this, you should read Getting Started With Cocoa.)
This example illustrates the dynamism of the Cocoa environment—the values of two user interface objects are kept synchronized without writing any code, even without compiling.
(Emphasis mine)
Huh? Wouldn't you need to create outlets? And an IBAction that goes something like
- (IBAction)takeFloatValueFrom:(id)sender {
self.slider.floatValue = [sender floatValue];
self.textField.floatValue = [sender floatValue];
}
Is this something Mac-specific? How do you actually hook up two controls with target-action in a XIB without writing any code and have their values locked?
When you're setting up an interface in Interface Builder, you can specify that it sends a message to another object whenever it changes in some way. What this example is showing is that you can hook these two objects up such that whenever the slider changes, it sends the message takeFloatValueFrom: to the text field, and vice-versa.
takeFloatValueFrom: is a method defined on NSControl, and both a text field and a slider are subclasses of NSControl.

single cocoa touch view to emulate terminal window for readline input and text output

I want to develop an iPad app which contains a single window that emulates a terminal for both input and output. The application (J) is a textbased programming language interpreter which does not really need a terminal window but can use readline from such a window for input. How can such a window/view be created in Xcode3 with Objective-C?
I have found the source code for readline on github.com, but I am not clear how a single window can be linked up for both the input and output.
Basic idea is these.
Create UITextView and set the delegate to a subclass of UIViewController.
For input, implement this method (UITextViewDelegate protocol) in the subclass of UIViewController.
When got enough characters to process, do it.
– textView:shouldChangeTextInRange:replacementText:
For output, just add text to text property of NSTextView.

I need to know when a textfield is done being edited

I have a class that contains several textfields. I need to know when one is done being edited and send the new information to one of my other objects.
This question seemed similar but in Objective C? The buttons should be visible when the user is done entering the value in the textfield
Objective-j doesn't have the same functions.
Browsing the documentation I found several functions that seemed like they might be able to help such as, textDidEndEditing but didn't understand how to use it. There are several more that sound related and I don't know what to use.
Summary: when the textfield is done being edited I need to perform another function. Also there are multiple textfields so I need to know which one is edited.
controlTextDidEndEditing is the delegate method you should implement. Or you can just set the target/action of the textfield

How can I press a button to play a custom sound?

I'm a complete programming novice and I was wondering how I could have several buttons that play different sounds. I've searched all around and can't figure out this simple task. Thanks!
It's a simple task once you know enough about Objective-C and the Cocoa (Cocoa-Touch on iPhone) frameworks.
Rather than just searching the net for examples you would be better off looking for references on how to program Objective-C and Cocoa.
The steps are:
In Xcode, create a controller class that has a method such as this: - (IBAction)playSound:(id)sender;
Create the UI using Interface Builder.
Place the buttons you want on this interface and configure their labels.
For each of the buttons set a numeric tag (you can do this in interface builder).
For each of the buttons set the target to be the controller and the action to be the method you created in step 1. (You do this by ctrl dragging the button onto the controller object in Interface Builder)
In the controller class, fill out the method by writing a for loop that checks the tag of of the button (which you can get through the 'sender' object and then play a sound based on the tag.
Depending on your level of experience with Cocoa, this might not make sense right now, but if you read through the references and tutorials for Objective-C and Cocoa each of these steps will become clearer and you'll be able to complete this simple task yourself.

How do I populate an NSPopupButton with an array of strings?

Simple question, but I am struggling a little to understand how Interface Builder interacts with the rest of the program developed in X-Code.
My UI has an NSPopupButton that I would like to fill with an array of strings that I provide. I have a controller class that defines the method to execute when the button is clicked. Is that where I would populate the NSPopupButton? It seems like I would need to initialize is somewhere, but I am confused about exactly where to do it. I know I need to use addItemsWithTitles, but where do I call that?
Assuming the list isn't changing over time, awakeFromNib (in the controller) would be a good place to populate the menu. If it's dynamic, then you'd want to populate it when the source of those strings changes.