Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

UIButton - crash on didReceiveMemoryWarning #67

Closed
edowling opened this issue Feb 9, 2012 · 5 comments
Closed

UIButton - crash on didReceiveMemoryWarning #67

edowling opened this issue Feb 9, 2012 · 5 comments

Comments

@edowling
Copy link

edowling commented Feb 9, 2012

Adding an event handler to a UIButton that pushes a view controller onto the current navigation controller causes a crashes in [super didReceiveMemoryWarning];

The offending code is:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(194, 4, 126, 70)];
[button setBackgroundColor:[UIColor clearColor]];
[button addEventHandler:(BKSenderBlock)^ {

   AViewController *viewController = [[AViewController alloc] initWithNibName:@"AViewController" bundle:nil]
   [self.navigationController pushViewController:viewController animated:YES];

 } forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

Countless hours of debugging and on-device and simulator memory warnings have pinpointed the [button addEventHandler] to be the culprit.

Running the block in the main thread using GCD does not solve the crash.

@zwaldowski
Copy link
Collaborator

Thanks for the report. It'll be looked into shortly.

@zwaldowski
Copy link
Collaborator

I'm unable to reproduce it. What SDK/OS version is this on? Where (code-wise) is the button being initialized? Not only should -addEventHandler: not being getting called on -didReceiveMemoryWarning, but -addEventHandler: doesn't get called when the button is tapped anyway.

@a2
Copy link
Collaborator

a2 commented Feb 9, 2012

It seems you're passing a BKBlock but typecasting it as a BKSenderBlock.

Try it this way:

[button addEventHandler: ^(id sender) {

   AViewController *viewController = [[AViewController alloc] initWithNibName:@"AViewController" bundle:nil]
   [self.navigationController pushViewController:viewController animated:YES];

 } forControlEvents:UIControlEventTouchUpInside];

@edowling
Copy link
Author

Thanks for that! Sorry for wasting your time :)

@a2
Copy link
Collaborator

a2 commented Feb 13, 2012

No worries! Glad I could have helped!

@a2 a2 closed this as completed Feb 13, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants