DigitalBrain_DEV
DigitalBrain_DEV

Reputation: 1103

Simultaneous push ViewController

I have a "strange" issue with xcode5 and the new sdk. I have a Navigation controller. The root view controller has 2 buttons, both buttons are linked to an action that push a viewcontroller into navigation-controller's stack. If I run this project on XCode5 and if I push both buttons simultaneous the navigation controller going "crazy" with the message: "nested push animation can result in corrupted navigation bar".

But if I try the same code with xCode4 the application work also if I push simultaneous. Have I forgot something?? Is this a already known behaviour? There are a way to fix this issue? Thanks a lot

This is the simple sample code
' -(void)viewDidLoad { [super viewDidLoad];

UIButton *BTN1= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BTN1 addTarget:self action:@selector(ACTION) forControlEvents:UIControlEventTouchUpInside];
[BTN1 setTitle:@"XXX" forState:UIControlStateNormal];
[BTN1 setFrame:CGRectMake(0, 100, 100, 100)];


UIButton *BTN2= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[BTN2 addTarget:self action:@selector(ACTION) forControlEvents:UIControlEventTouchUpInside];
[BTN2 setFrame:CGRectMake(0, 200, 100, 100)];
[BTN2 setTitle:@"XXX" forState:UIControlStateNormal];
[self.view addSubview:BTN1];
[self.view addSubview:BTN2];

}



-(void)ACTION
{
FirstViewController *fi = [[FirstViewController alloc] init];
[self.navigationController pushViewController:fi animated:YES];


}`

Upvotes: 2

Views: 628

Answers (2)

Tushar
Tushar

Reputation: 88

Use button.exclusiveTouch = YES; on each of your buttons. You will need to hook them up to UIButtons and set the property in viewDidLoad for example.

Upvotes: 0

Totumus Maximus
Totumus Maximus

Reputation: 7583

To prevent the navigation stack from being corrupted when pressing 2 buttons simultaneously, it is best to set exclusive touch to the buttons you are working with. This way you can prevent multiple triggers of the button action and prevent multiple ViewControllers from being pushed to the stack and corruption to happen.

[yourButton setExclusiveTouch:YES]; 

Upvotes: 4

Related Questions