내 프로젝트에서 세그먼트 컨트롤을 설정했습니다. 내 설정 장면에서 방향을 사용하여 왼쪽 또는 오른쪽으로 가로 방향을 제어하고 싶습니다.UISegmentedControl에서 값을 변경하는 방법?
#import <UIKit/UIKit.h>
@interface SettingsViewController : UIViewController
{
IBOutlet UISegmentedControl *orientation;
}
@property (nonatomic, retain) UISegmentedControl *orientation;
- (IBAction) setOrientation;
@end
여기가 SettingsViewController.m 내 코드 내 스토리 보드에서 설정에 있고 여기에 내 코드 내 SettingsViewController.h에
#import "SettingsViewController.h"
@implementation SettingsViewController
@synthesize orientation;
- (IBAction)setOrientation
{
NSLog(@"index = %d\n", orientation.selectedSegmentIndex);
if (orientation.selectedSegmentIndex == 0) {
NSLog(@"left\n");
}
if (orientation.selectedSegmentIndex == 1) {
NSLog(@"right\n");
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
@end
값이없는 이유를 궁금 해서요 컨트롤의 오른쪽을 선택하면 0에서 1로 변경됩니다. 또한 나는 내 .h에서 IBOutlet을 선언해야하는지에 대해 궁금해했다. 왜냐하면 분할 된 컨트롤을 콘센트로 사용하지 않기 때문이다. 방금 선택한면을 선택한 다음 앱의 방향을 설정하는 데 사용합니다.
감사합니다. 그것은 작동한다 :) (나는 그것을 투표 할 것이나 나는 그것을하기에 충분한 충분한 담당자가 없다 : /) – sbru