开发者

How to I respond to a user pressing a UISegment?

开发者 https://www.devze.com 2023-01-23 01:57 出处:网络
How to I respond to a user pressing a UISegment? Is there a delegate, or must I programmatically (or Interface Builder), attach the开发者_运维知识库 selectors?If you prefer to do it in code you can us

How to I respond to a user pressing a UISegment? Is there a delegate, or must I programmatically (or Interface Builder), attach the开发者_运维知识库 selectors?


If you prefer to do it in code you can use:

[segmentedControl addTarget:self action:@selector(didSelectIndex:) forControlEvents:UIControlEventValueChanged];

And this is then the method that would be called

- (void) didSelectIndex: (id) sender
{
    NSLog(@"%@",[(UISegmentedControl *)sender titleForSegmentAtIndex:[(UISegmentedControl *)sender selectedSegmentIndex]]); //replace this with your code
}

If you prefer to use IB, right click on your UISegmentedControl select Value Changedand then attach it to the desired method in your first responder.


UISegmentedControl subclasses UIControl and sends out the control event UIControlEventValueChanged whenever the selected segment changes. You can add a target/action pair for this event in code, or you can do it with the normal control-click-and-drag in IB.

0

精彩评论

暂无评论...
验证码 换一张
取 消