0

我不知道为什么我会遇到这个问题。

详细信息 - 我的应用程序中有一个标签栏控制器。在一个选项卡上,我有一个包含一些按钮的表单。我正在设置这些按钮的标题。现在,当我更改选项卡并返回同一个选项卡时,所有按钮标题都会变暗。

我也附上屏幕截图。

任何帮助,将不胜感激。

谢谢 !!

第一的 第二 在此处输入图像描述

编辑:这是我如何创建按钮的代码 -

-(void)viewWillAppear:(BOOL)animated
{
    float yFrame =310.0f;
            for(int i =0;i<7;i++){

                openPickerButton=[UIButton buttonWithType:UIButtonTypeCustom];
                openPickerButton.frame = CGRectMake(29.0, yFrame+10.0, 280.0, 48.0);
                openPickerButton.tag=i;
                openPickerButton.backgroundColor=[UIColor clearColor];
                [openPickerButton setTitle:[formButtonTitle objectAtIndex:openPickerButton.tag] forState:UIControlStateNormal];

                openPickerButton.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:16];
                [openPickerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
                openPickerButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                openPickerButton.showsTouchWhenHighlighted = YES;
                [openPickerButton addTarget:self action:@selector(PickChoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [setPreferencesFormScrollView addSubview:openPickerButton];
                yFrame+=60.0f;
            }
}
4

2 回答 2

1

而不是在 viewWillAppear 方法中创建按钮,而是在 viewDidLoad 方法中创建按钮

于 2012-06-01T19:18:00.917 回答
1

那么在 viewDidLoad 中,您的对象会被调用一次。(一旦视图被加载。停止)在 viewWillAppear 中,每次视图出现时它们都会被调用。

- (void)viewDidLoad
{
    [super viewDidLoad];
    float yFrame =310.0f;
            for(int i =0;i<7;i++){

                openPickerButton=[UIButton buttonWithType:UIButtonTypeCustom];
                openPickerButton.frame = CGRectMake(29.0, yFrame+10.0, 280.0, 48.0);
                openPickerButton.tag=i;
                openPickerButton.backgroundColor=[UIColor clearColor];
                [openPickerButton setTitle:[formButtonTitle objectAtIndex:openPickerButton.tag] forState:UIControlStateNormal];

                openPickerButton.titleLabel.font=[UIFont fontWithName:@"Helvetica" size:16];
                [openPickerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
                openPickerButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                openPickerButton.showsTouchWhenHighlighted = YES;
                [openPickerButton addTarget:self action:@selector(PickChoreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
                [setPreferencesFormScrollView addSubview:openPickerButton];
                yFrame+=60.0f;
            }
}
于 2012-06-01T19:32:38.713 回答