gpt4 book ai didi

ios - UISegmentedControl 切换 View 它重置

转载 作者:行者123 更新时间:2023-11-29 01:57:52 25 4
gpt4 key购买 nike

我有一个 UISegmentedControl 和两个 ViewController。每个页面上都有一个按钮,用于浏览两个 View ,但是当我将 Segmentcontrol 设置为某个 View 并返回时,它会重置为原始 View 。

这是我想要做的,第 1 页上的用户单击设置,然后 UISegmentedControl 选择配色方案并返回。 (但是我如何从 View #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,在 View #1 上。所以我无法访问它。当我返回查看 #2 时,加上段控制重置。

最佳答案

View #2 可能在您返回 View #1 时被释放,假设您弹出或关闭以返回。当您再次转到 View #2 时,它是一个新实例,因此分段控件当然会显示默认选择。要更改第一个 Controller 中的标题属性,您应该使用在 Controller #2 中定义的委托(delegate)协议(protocol)。使用它将颜色和字体属性传递回 Controller #1,并让该 Controller 设置自己的标题特征。使用委托(delegate)模式将数据发送回之前的 Controller 是 Apple 通常使用的范例,您可以在文档中阅读相关内容。

关于ios - UISegmentedControl 切换 View 它重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30652286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com