0

I have been trying to get a Modal view to display with a transparant background - which I have managed programatically with the help of @Tommaso Resti Modal View Transparant background - stop lower layer hiding?

Prior to implementing the modal view programatically I had it connected via a segue - the modal (which has a class of shareScreenViewController) contains to buttons with ibconnections to methods in its .m file. The methods fired without issue with teh segue connection - but now the view is added programatically when i click on a button the app crashes with the error -

Thread1:Exc_Bad_Access(code=1...  

shown in the screenshot below - I have added breakpoints and it appears that the method isnt even called before the app crashes - No idea whats going on - can anyone offer any advice!?

enter image description here

UPDATE: from @Larme 's help below I enabled NSZombie and now get this error -

2013-11-15 15:04:37.754 GetPTFit[1574:60b] Animation completed 2013-11-15 15:04:39.419 GetPTFit[1574:60b] *** -[shareScreenViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x16e1f2d0 (lldb)

The code i'm using to setup the modal is as follows -

- (IBAction)shareBtn:(id)sender {


UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone"
                                                         bundle: nil];
UIViewController *myModalController = [mainStoryboard instantiateViewControllerWithIdentifier:@"shareScreenViewController"];
[myModalController.view setFrame: CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view addSubview: myModalController.view]; /* UPDATED HERE! */


/* Animate it from the bottom */
[UIView animateWithDuration:.5 animations:^{
    CGAffineTransform move = CGAffineTransformMakeTranslation(0, -[UIScreen mainScreen].bounds.size.height);
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    myModalController.view.transform = move;   /* UPDATED HERE */
} completion:^(BOOL finished) {
    if(finished) {
        NSLog(@"Animation completed");
    }
}];

}

Community
  • 1
  • 1
Dancer
  • 17,035
  • 38
  • 129
  • 206
  • 2
    Did you set NSZombie to get what object was released before you want to access it? – Larme Nov 15 '13 at 14:55
  • nope - sorry no idea what that means - (reasonably new to IOS dev and only used storyboard in the past). How would I do that? – Dancer Nov 15 '13 at 14:57
  • 2
    http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode – Larme Nov 15 '13 at 14:59
  • cool - makes sense - ok now I get this error - 2013-11-15 15:04:37.754 GetPTFit[1574:60b] Animation completed 2013-11-15 15:04:39.419 GetPTFit[1574:60b] *** -[shareScreenViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x16e1f2d0 (lldb) – Dancer Nov 15 '13 at 15:05
  • Seems that you wanted to do performSelector:WithObject:withObject: and it got release before. So you want your shareScreenViewController to do something although it doesn't exists anymore. More code should be good to help you. – Larme Nov 15 '13 at 15:07
  • Cheers @Larme - Added above – Dancer Nov 15 '13 at 15:15
  • Ok. Just to be clear. It's not really related to NSZombie. NSZombie is mostly a tool to detect this kind of error (what object was release too soon). – Larme Nov 15 '13 at 15:19
  • fair enough - edited above accordingly – Dancer Nov 15 '13 at 15:20
  • 1
    just try to add myModalController as a child view controller. add [self addChildViewController: myModalController] after you add the subview. – Danyun Liu Nov 15 '13 at 16:21
  • Cheers @Danyun - That worked! If you add an answer I'll give you a tick. Would I have to do anything special to remove that from memory awhen closing the modal? – Dancer Nov 15 '13 at 17:05
  • 1
    You need to do nothing about that if you are using arc. – Danyun Liu Nov 15 '13 at 19:00
  • cool - add your comment as an answer and i'll tick it off as its all working fine – Dancer Nov 18 '13 at 10:41

0 Answers0