3

UISegmentedControl error on iOS 4.x

 1 year ago
source link: https://fann.im/blog/2012/07/18/uisegmentedcontrol-error-on-ios-4-dot-x/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

UISegmentedControl error on iOS 4.x

Jul 18, 2012

Code 1:

self.segmentedControl = [[[UISegmentedControl alloc] init] autorelease];
[_segmentedControl setSelectedSegmentIndex:0];
[_segmentedControl addTarget:self
                      action:@selector(segmentedControlSwitch)
            forControlEvents:UIControlEventValueChanged];

Code 2:

self.segmentedControl = [[[UISegmentedControl alloc] init] autorelease];
[_segmentedControl addTarget:self
                      action:@selector(segmentedControlSwitch)
            forControlEvents:UIControlEventValueChanged];
[_segmentedControl setSelectedSegmentIndex:0];

注意 [_segmentedControl setSelectedSegmentIndex:0]; 的位置,在 iOS 4.x 下,Code 2 代码在设置 selectedSegmentIndex 的时候会执行一次 segmentedControlSwitch 方法。在 iOS 5+ 没有这个问题。

Was this page helpful?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK