Add selectors to multiple segmented controls in NIB file
I have two UIbutton
s, and I want to assign the two buttons to a UITextView
so that when one of the buttons is pressed, the text vie开发者_C百科w content changes from what it had when previous button was pressed. I want to do this using a segmented control. How do I assign each segmented control different selectors in the NIB file?
As mentioned you have to connect your IBAction to your UISegmentedControl
in IB with the valueChanged:
option (i think you usually set touchUpInside for uibuttons), then try this
- (IBAction)changeType:(id)sender{
//segControl is an instance of UISegmentedControl
segControl = sender;
if(segControl.selectedSegmentIndex==0){
//do something
}
else if (segControl.selectedSegmentIndex==1){
}//and so on
}
Hope this helps.
You can assign the segment control to a single IBAction
. In that method use segment control's selectedSegmentIndex
to identify which section is pressed and call the later functions accordingly.
精彩评论