我想将分段控件存储到属性列表中,也可以从plist中检索。 那我该怎么做呢?
答案 0 :(得分:2)
在viewcontroller中创建一个UISegmentControl Outlet
IBOutlet UISegmentedControl *mySegment;
将其连接到Interface Builder中的UISegmentControl
添加此IBAction方法并将其连接到Interface Builder
- (IBAction) changeSegment: (id) sender {
//save UISegment value in NSUserDefaults
[[NSUserDefaults standardUserDefaults] setInteger:[sender selectedSegmentIndex] forKey:@"savedSegment"];
}
在viewDidLoad
中加载视图时恢复保存的值- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mySegment.selectedSegmentIndex = [[NSUserDefaults standardUserDefaults] integerForKey:@"savedSegment"];
}