ios - I think i have done some mistake in allocating segmentcontrol..i am getting an error [unrecognized selector sent to instance] -
segcontrol = [[uisegmentedcontrol alloc] initwithitems:[nsarray arraywithobjects:@"mind", @"munches", nil]]; segcontrol.frame=cgrectmake(cgrectgetwidth(self.view.frame)/4.5, self.view.frame.size.height/4, cgrectgetwidth(self.view.frame)/1.8, cgrectgetheight(self.view.frame)/12); [segcontrol addtarget:segcontrol action:@selector(segtap:) forcontrolevents:uicontroleventvaluechanged]; [segcontrol setselectedsegmentindex:0]; [segcontrol settintcolor:[uicolor bluecolor]]; segcontrol.layer.cornerradius=5; [self.view addsubview:segcontrol]; -(void)segtap:(id)sender{ if (segcontrol.selectedsegmentindex==0) { self.view.backgroundcolor=[uicolor bluecolor]; }else if (segcontrol.selectedsegmentindex==1){ self.view.backgroundcolor=[uicolor redcolor]; } }
you adding segmentcontrol
object segcontrol
target segment action. rather object self
should added target. change code below , go.
[segcontrol addtarget:self action:@selector(segtap:) forcontrolevents:uicontroleventvaluechanged];
Comments
Post a Comment