【发布时间】:2012-08-11 03:07:54
【问题描述】:
我在我的项目中设置了分段控件。我想在我的设置场景中使用它来控制方向是横向左侧还是横向右侧。我已经在我的情节提要中进行了设置,这是我的 SettingsViewController.h 中的代码
#import <UIKit/UIKit.h>
@interface SettingsViewController : UIViewController
{
IBOutlet UISegmentedControl *orientation;
}
@property (nonatomic, retain) UISegmentedControl *orientation;
- (IBAction) setOrientation;
@end
这是我在 SettingsViewController.m 中的代码
#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 因为我不使用分段控件作为出口。我只是使用它来获取选择了哪一侧,然后使用它来设置应用程序的方向。
【问题讨论】:
标签: xcode xcode4.3 uisegmentedcontrol