Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

marcmeezy

macrumors newbie
Original poster
Feb 5, 2011
5
0
Hello all..

I am new to the Objective-C language but I have programmed in a couple other languages.

I thought I would start with a simple application to test the waters..

There is a stock profit calculator app and they link the radio button with a text field so that when the radio button is selected the corresponding text field is not editable and the value is calculated from the other two fields. I'd like to do something similar to this.

Here is a link of the app - http://www.sspi-software.com/stockcalc_macx.html

How can I achieve this? I've looked around in the docs but it seems I'm over looking something..

I greatly appreciate any input and thanks for your time,

Marc
 
Where are you running into trouble?

Do you understand how to make the text fields and radio buttons separately?

Hardcode Boolean values to substitute for the radio buttons and Get tha working, then get the radio buttons to work on their own.

Post code you are having trouble with.

B
 
Radio buttons are often (not always) done as cells in a NSMatrix — the matrix class even has a setting to facilitate this. Thus, a single action assigned to the matrix could look at the button selection to decide how the fields need to be enabled.
 
Alright so I figured out how to determine which radio button is selected..

selectedRow.. You guys had mentioned to give the radio buttons Boolean values and I'm not sure how to do that.. As you can see I've set up a series of if-statements.. I'm sure there is a better way to do this.

My question now is how do I make a NSTextField not editable when clicking on it's corresponding radio button.

I went to Cmd-4 and tried to bind it but it keeps crashing.. I'm guessing because it needs a Boolean variable. How can I go about this?


- (IBAction)convertSharePrice:(id)sender {

int cellTag;

cellTag = [buyRadioGroup selectedRow];

NSLog(@"Selected cell is %d", cellTag);

if (cellTag == 0) { /* calculate share price */

float numShares = [dispNumShares floatValue];
float cash = [dispCashOutlay floatValue];
float calculatedSharePrice = [converter numberOfShares:numShares amountCash: cash];

[dispSharePrice setFloatValue:calculatedSharePrice];

} else if (cellTag == 1) { /* Calculate number of shares */

float sharePrice = [dispSharePrice floatValue];
float cash = [dispCashOutlay floatValue];
float calculatedNumShares = [converter sP:sharePrice amountCash:cash];

[dispNumShares setFloatValue:calculatedNumShares];

}
}


Thanks again for your help.
 
So I used this [dispSharePrice setEditable:(BOOL)flag];

to disable the TextField.. But I'm using an invisible button that has a key equiv. of the return key.

When I change radio buttons the text field is disable only after I hit the return key.

How can I have the text fields updated automatically (instead of having to go through an invisible button and link it to the return key) on a click or tab of a different text field.

Essentially I'd like the program to detect that the radio button is selected already at run time. i've tried isSelected in my action method.. but it only works when the radio button is clicked.
 
Last edited:
How can I have the text fields updated automatically (instead of having to go through an invisible button and link it to the return key) on a click or tab of a different text field.

One possible solution to set your app delegate (assuming you're not using a window delegate) as the delegate of each of the text fields. Then implement - (void)controlTextDidChange:(NSNotification *)aNotification in your app delegate. This method will be called every time one of the text fields changes. You could recalculate and update from there. However it would be called for each keystroke, so you'd need to be prepared for invalid and incomplete input.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.