0 Replies - 4394 Views - Last Post: 17 November 2012 - 03:23 AM

#1 Mutant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-November 12

UISegmentedControl index doesnt update when touched

Posted 17 November 2012 - 03:23 AM

Hello I am having a problem updating the index of my segmented controller. The following code comes from the calcualate class.

+ (NSString *) calculate:(NSString *)height:(NSString *)weight{
double bmiVal = 0;
MBBFirstViewController *fVC;
NSLog(@"%d", [[fVC heightSegment]selectedSegmentIndex]);
NSLog(@"%d", [[fVC weightSegment]selectedSegmentIndex]);
if ([[fVC heightSegment]selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 10.5555;
}else if ([[fVC heightSegment] selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 11.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 0 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 12.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 13.5555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 14.5555;
}else if ([[fVC heightSegment] selectedSegmentIndex] == 1 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 15.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 0) {
value = 16.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 1) {
value = 17.55555;
}else if ([[fVC heightSegment]selectedSegmentIndex] == 2 && [[fVC weightSegment]selectedSegmentIndex] == 2) {
value = 18.5555;
}
}
NSString *bmiV = [NSString stringWithFormat:@"%.2f",bmiVal];
return bmiV;
}

This code is from the viewcontroller.m class

- (IBAction)calculateTotal:(id)sender {
NSString *h = [heightField text];
NSString *w = [weightField text];
yourBmiField.text = [calculate yourCalculation:h:w];
}

And this is from the viewcontroller.h

@interface MBBFirstViewController : UIViewController <UITextFieldDelegate>{
UITextField *heightField;
UISegmentedControl *heightSegment;
UITextField *weightField;
UISegmentedControl *weightSegment;
}
@property (strong, nonatomic) IBOutlet UITextField *heightField;
@property (strong, nonatomic) IBOutlet UISegmentedControl *heightSegment;
@property (strong, nonatomic) IBOutlet UITextField *weightField;
@property (strong, nonatomic) IBOutlet UISegmentedControl *weightSegment;
- (IBAction)calculateTotal:(id)sender;
@end


I have left out the main calculations to make this shorter. When I run this the selected segment always stays at 0.

Can someone see why this is happening and if possible tell me how I could fix.

Any help would be greatly appreciated.

Thanking You

Is This A Good Question/Topic? 0
  • +

Page 1 of 1