gpt4 book ai didi

ios - 通过 ViewControllers 传递数据 - 进行设置页面

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:17 28 4
gpt4 key购买 nike

所以我遇到这个问题已经有一段时间了,如果有人能带我走上正确的道路,我将不胜感激。基本上我正在制作一个应用程序,但有一个设置按钮。每当我启用我的 SegmentedControl 或 UISWITCH 时,我都会返回到默认状态。我还想有一个分段控件来更改颜色。我已经设置了颜色,但我想更改的所有信息都在 View Controller #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 Controller 上,因此它自动不起作用。我怎样才能解决这个问题。请将我链接到某个地方/以一种不复杂的方式向我展示。 (我也会有很多标签)

最佳答案

为此,我通常使用在文件级别声明的结构(不嵌套在任何类中)。因此,它应该可以在整个应用程序中访问。更改所选段时设置值;在加载 View Controller 时获取值。这是 Swift 中的示例:

struct setStruct {
var selSeg: Int = 0
}
var settings = setStruct()

在设置View Controller viewDidLoad:

Controller.selectedSegmentIndex = settings.selSeg

在分段控件的 IBAction 中:

settings.selSeg = Controller.selectedSegmentIndex

关于ios - 通过 ViewControllers 传递数据 - 进行设置页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30609351/

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