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