0

I've a custom cell for my table view,
enter image description here

I want to assign value changed event for the segment ON/OFF. Ideally, the event sent a asynchronous request depending on the label value as a POST argument to a web service to update the value.

I thought there are 2 ways to do the same:
1. From IB make a IBAction for the event valueChanged in the CustomCell.m file.
2. Dynamically assign a handler, like you assign to the function, using addTarget.

Is my approach correct?? If yes, could someone please tell me/point to some tutorial where i can learn to add event handlers for the valueChanged event. The handler must take atleast one argument.

anotherCoder
  • 712
  • 3
  • 11
  • 25

2 Answers2

0

Tutorial for segment control value changed event

This might help you.

iAppDeveloper
  • 1,088
  • 1
  • 8
  • 16
0
    NSArray *itemArray = [NSArray arrayWithObjects: @"ON", @"OFF", nil];
        self.snoozeSgCon= [[UISegmentedControl alloc] initWithItems:itemArray];
        self.snoozeSgCon.frame = CGRectMake(15, 330, 280, 40);
        self.snoozeSgCon.segmentedControlStyle = UISegmentedControlStylePlain;
        self.snoozeSgCon.selectedSegmentIndex = 1;
        [self.snoozeSgCon addTarget:self action:@selector(segmentActionSnooze:) forControlEvents:UIControlEventValueChanged];
        [self.cell.contentView addSubview:self.snoozeSgCon];

-(void)segmentActionSnooze:(id)sender
{
    switch ([self.snoozeSgCon selectedSegmentIndex])
    {
        case 0:
        {
           // code for ON BUtton
        }
        case 1:
        {
            // code for OFF BUtton
        }

     }
}
iPatel
  • 46,010
  • 16
  • 115
  • 137