Вопрос

I did actually make a segue from my viewcontroller to itself by using a hidden button and then another one that makes the segue. Just for the sake of clarification, say I want to change the view bg color by using a segue. The issue here is that the view returns to its first state as if I run it again because it goes through the viewdidload and the viewdidappear and so. Is there a way or a workaround that I can utilize to continue from the last state of my view?

What do I need to add to this code for example:

- (IBAction)changeColor:(id)sender {
    [self performSegueWithIdentifier:@"changeC" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ViewController* controller = [segue destinationViewController];

    controller.view.backgroundColor = [UIColor blueColor];   
}
Это было полезно?

Решение

I'm not even going to ask why you would ever actually want to do that, but you could just have a BOOL like shouldReloadView, and set that to NO in prepareForSegue:. Then, within viewDidLoad and viewWillAppear just check for that BOOL before doing any setup.

Другие советы

Best way is to add a color variable to you header file:

 @property (nonatomic, strong) UIColor *backgroundColor;

Then customize the init function in the implementation file to require a UIColor.

Then forget about segues just do the following.

  YourViewController *viewController = [[YourViewController alloc] initWithBackgroundColor:[UIColor someColor]];

  [self.navigationController pushViewController:YourViewController animation:YES];

Et voila.

@sfeuerstein is correct based on his suggestion

- (IBAction)changeColor:(id)sender {
[self performSegueWithIdentifier:@"changeC" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   ViewController* controller = [segue destinationViewController];

   controller.state = YES;  // set bool value in your controller state
}

make a check in your view controller

-(void)ViewDidLoad{  

if(NewState){
    controller.view.backgroundColor = [UIColor blueColor]; 
   }
else{
   controller.view.backgroundColor = [UIColor whiteColor]; 
   }
}

but i still dont know , why you are trying to do something like this . its not good approach.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top