How can I make one calculate button by using a UISegmentControl where you can choose between male of female?
I tried this, but then I need to declare cal again...
Quote:
- (IBAction) changeSegment{
if (genSegment.selectedSegmentIndex == 0) {
int a = [weightTF.text intValue];
int b = [lenghtTF.text intValue];
int c = [ageTF.text intValue];
int cal = 66 + (13.7 * a) + (5 * b) - (6.8 * c);
}
if (genSegment.selectedSegmentIndex == 1) {
int a = [weightTF.text intValue];
int b = [lenghtTF.text intValue];
int c = [ageTF.text intValue];
int cal = 655 + (9.6 * a) + (1.8 * b) - (4.7 * c);
}
calcMen and calcWomen really shouldn't be IBActions because there's no place I can see you want to do only one or the other. You might rename "changeSegment" to something like "doCalculate" because that's what it's for.
And I can't see anything you posted that should crash, so you'll need to specify what line is crashing and any messages you are getting.
It works fine now by using only the UISegmentControl, but I still can't make use of the calculate-button.
The total value only changes when I switch from male to female or female to male.
I had in mind that it only calculates the total value depending on the UISegmenControl just by clicking the calculate button.
It works fine now by using only the UISegmentControl, but I still can't make use of the calculate-button.
The total value only changes when I switch from male to female or female to male.
I had in mind that it only calculates the total value depending on the UISegmenControl just by clicking the calculate button.
Thanks
You don't even need an IBAction for the UISegmentControl, just an IBOutlet. Than in the buttons touchUpIniside action put the code
Code:
-(IBAction)yourButtonPressed {
if (yourSegementControl.selectedSegmentIndex == 0) {
[self calcMen];
} else if (yourSegmentedControl.selectedSegmentIndex == 1) {
[self calcWomen];
}
}