ios - How to get UISwitch with its tag? -


i have function call each time open controller draw me uiswitch.

 int y = 0;     (int = 0 ; < daysarray.count ; i++)     {          uiswitch * daysswitch = [[uiswitch alloc]initwithframe:cgrectmake(255, y, 20, 20)];         [daysswitch settag:i];         [daysswitch seton:yes];          [daysswitch addtarget:self action:@selector(switchpressed:) forcontrolevents:uicontroleventvaluechanged];               [self.availabletimesscrollview addsubview:daysswitch];          y = y+ 130;       } 

i trying set of uiswitch on or off according tag.

 uiswitch * switch = (uiswitch *) [self.view viewwithtag:0] [switch seton:no]; 

but doesn't change or seem affect it.

so if not right answer tag of uiswitch set on or off , how can it?

the default tag view 0.

you're adding these uiswitch instances self.availabletimesscrollview calling viewwithtag: on self.view. method return nearest ancestor given tag, it's returning self.availabletimesscrollview.

assuming view hierarchy looks below, nearest ancestor tag 0 self.availabletimesscrollview.

self.view     self.availabletimesscrollview (tag 0)          switch1 (tag 0)          switch2 (tag 1)          switch3 (tag 2)          ... 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -