0
我有一个UISegmentedControl和两个ViewControllers。每个页面上的按钮都可以浏览这两个视图,但当我将Segmentcontrol设置为某个特定的视图并返回时,它会重置为原始视图。UISegmented控制切换视图重置
继承人我想要做的,页面1上的用户单击设置,然后UISegmentedControl选择配色方案并返回。 (但我怎么从视图#1访问标签)
继承人到目前为止我的代码:
- (IBAction)colorController:(id)sender {
if (Controller.selectedSegmentIndex == 0) {
//App title text color
appTitle.textColor = [UIColor colorWithRed:1.00 green:1.00 blue:0.00 alpha:1.0];
//Background color when selected
Controller.tintColor = [UIColor colorWithRed:1.00 green:1.00 blue:0.00 alpha:1.0];
//The font of the selected
NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor],NSForegroundColorAttributeName,
nil];
[Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];
}
if (Controller.selectedSegmentIndex == 1) {
//App title text color
appTitle.textColor = [UIColor colorWithRed:0.00 green:0.66 blue:1.00 alpha:1.0];
//Background color when selected
Controller.tintColor = [UIColor colorWithRed:0.00 green:0.66 blue:1.00 alpha:1.0];
//The font of the selected
NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
nil];
[Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];
}
if (Controller.selectedSegmentIndex == 2) {
//App title text color
appTitle.textColor = [UIColor colorWithRed:0.98 green:0.22 blue:0.22 alpha:1.0];
//Background color when selected
Controller.tintColor = [UIColor colorWithRed:0.98 green:0.22 blue:0.22 alpha:1.0];
//The font of the selected
NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
nil];
[Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];
}
if (Controller.selectedSegmentIndex == 3) {
//App title text color
appTitle.textColor = [UIColor colorWithRed:0.15 green:0.82 blue:0.44 alpha:1.0];
//Background color when selected
Controller.tintColor = [UIColor colorWithRed:0.15 green:0.82 blue:0.44 alpha:1.0];
//The font of the selected
NSDictionary *fontColor = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[Controller setTitleTextAttributes:fontColor forState:UIControlStateSelected];
}
}
现在。 appTitle,位于视图#1。所以我无法访问它。加上段控制重置,当我回去查看#2。
使用委托并通过以下方式手动设置:'self.segmentControl.selectedSegmentIndex' – 0yeoj