Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Fuzzball27

macrumors member
Original poster
Aug 8, 2011
30
1
I'm having an issue that I have localized to this block of code:
Code:
    UIColor *color;
    NSInteger pressed = ViewTwo.background.selectedSegmentIndex;
//background is an instance of UISegmentedControl
    if (pressed == 0) {
        color = [UIColor whiteColor];
    }
    else if (pressed == 1) {
        color = [UIColor grayColor];
    }
    else if (pressed == 2) {
        color = [UIColor blackColor];
    }
    else color = [UIColor whiteColor];
    self.window.backgroundColor = color;

My problem is that the background isn't changing colors when the color depends on the segmented control. I have verified that the code is being run; replacing the if statements with "color = [UIColor someColor];" works fine. Does anyone have an ide why my code isn't working?
 
At minimum I would verify a few things. First that ViewTwo and background are not nil here. Then, the value assigned to the pressed variable if the first two items are not nil.
 
At minimum I would verify a few things. First that ViewTwo and background are not nil here. Then, the value assigned to the pressed variable if the first two items are not nil.

I have verified that ViewTwo is nil. Besides the fact that ViewTwo has no value, I'm not quite sure what that means? How can I fix that?
 
I have verified that ViewTwo is nil. Besides the fact that ViewTwo has no value, I'm not quite sure what that means? How can I fix that?

It means that the variable, ViewTwo, does not point to any object.

To help further, we'd have to understand if & when you set ViewTwo up, and where the code sample above is in relation to that.
 
View two interface:
Code:
@interface SimonSecondViewController : UIViewController

@property (weak, nonatomic) IBOutlet UISegmentedControl *background;
@end

View one interface:
Code:
@interface SimonFirstViewController : UIViewController
{
    SimonSecondViewController *ViewTwo;
}

@property (weak, nonatomic) IBOutlet UIView *window;
@end

Code:
- (void)setBackgroundColor
{
    UIColor *color;
    NSInteger pressed = ViewTwo.background.selectedSegmentIndex;
    if (pressed == 0) {
        color = [UIColor whiteColor];
    }
    else if (pressed == 1) {
        color = [UIColor grayColor];
    }
    else if (pressed == 2) {
        color = [UIColor blackColor];
    }
    else color = [UIColor whiteColor];
    self.window.backgroundColor = color;
}
This ^^ is called by ViewDidAppear in the implementation of view one.
 
Unless this is an iPad app, you can only have one UIViewController on the screen at a time. I'm not yet familiar with iPad VC (UIViewController) differences. So...

You can't interact with the interface of a VC that isn't displayed on the screen. You don't show where and if you have instantiated (created an instance) ViewTwo. It sounds like you want to interact with ViewTwo while an instance of SimonFirstViewController is displayed. That isn't possible on an iPhone or iPod.

Describe in detailed steps what it is you want to do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.