ios - How can I implement a callback before UISegmentedControl change to a new segment? -


working uisegmentedcontrol want present warning before select index. problem action uicontroleventvaluechanged called after new segment has been selected. how can implement callback before uisegmentedcontrol changes segment , decide if should change?

you can sort of 'trick' control grabbing selectedsegmentindex value , setting controls selectedsegmentindex value -1, selection being deferred.

a basic example 2 segments -

- (ibaction)segmentedindexdidchange:(uisegmentedcontrol*)sender {      // grab segment index value , store      nsinteger indextoquery = sender.selectedsegmentindex;      // deselect segments while making decisions      sender.selectedsegmentindex = -1;      // have willchange scenario instead of didchange      switch (indextoquery) {          case 0: {              nslog(@"seg index change 0");              //.. stuff .. make decisions .. etc.               break;          }          case 1: {              nslog(@"seg index change 1");              //.. stuff               break;          }           default:              break;      } } // remember config segmented control after done 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -