0

i have tried to put glpaint in uiviewcontroller. i'm facing some wierd problem after dismissing the the view controller with glpaint, the uiview controller, which have the option to launch glpaint view controller, gets deallocated. but how this happens. its seems like a puzzle to me.

i think the whole view controller gets deallocated

-[CALayer setNeedsLayout]: message sent to deallocated instance xxxxxxx

download glpaint implmented in uiview controller

can someone please take a look and tell us why this happens or how to prevent it. thanks in advance!

edit:

painter *vpaint=[[[painter alloc] initWithNibName:@"painter" bundle:nil] autorelease];        
[self.navigationController pushViewController:vpaint animated:YES]; 

and then returning back causes that error

[self.navigationController popViewControllerAnimated:YES];

Solution(SO doenst allow me to answer my own question due low reputation?! anyway):

i found it!!!!!!! the xib file is a subclass of PaintingWindow which UIWindow. for the time being setting it as UIView as default, it works perfectly. i have to see where should i implement the gesture recognition. thanks for helping @shahid and @kai :D

Hashmat Khalil
  • 1,826
  • 1
  • 25
  • 49
  • You should post the relevant part of your code. – Kai Huppmann May 02 '12 at 11:25
  • i've added the code where it possibly happens, but xcode doesnt show and it jumps to main.m line UIApplicationMain(argc, argv, nil, nil); with that error message. the whole project is also attached you might take a look at it? thanks – Hashmat Khalil May 02 '12 at 11:36

1 Answers1

0

I think you are dismissing view controller incorrectly, According to the View Controller Programming guide for iPhone OS, this is incorrect when it comes to dismissing modal view controllers you should use delegation. So before presenting your modal view make yourself the delegate and then call the delegate from the modal view controller to dismiss.

refer to this.

Also remove this

[self.drawingView release];
[self.windows release]; 

and this from painter.m

self.window=nil;
self.drawingView=nil;
Community
  • 1
  • 1
Shahid Aslam
  • 2,585
  • 3
  • 24
  • 31
  • also tried painter *vpaint=[[[painter alloc] initWithNibName:@"painter" bundle:nil] autorelease]; [self.navigationController pushViewController:vpaint animated:YES]; and then [self.navigationController popViewControllerAnimated:YES]; but it didnt help either. i get the same deallocated message – Hashmat Khalil May 02 '12 at 11:13
  • you are not understanding, you need to initialize delegate go through this example http://www.hardcodedstudios.com/home/ryan-newsome/simpledelegatetutorialforiosdevelopment – Shahid Aslam May 02 '12 at 11:19
  • i'm trying it now. but still dont understand why should use delegate. i'm learning :-) – Hashmat Khalil May 02 '12 at 11:39
  • so i tried it with the delegate, but still the same error wether its presented modally or pushed as view. edit: the error message change a lil bit: -[CALayer superlayer]: message sent to deallocated instance. now its the superlayer -.- – Hashmat Khalil May 02 '12 at 11:47
  • The second error was you are adding back button to self.window change that to [self.view addSubview:rootview]; – Shahid Aslam May 02 '12 at 11:51
  • but after delegate you didn't need that – Shahid Aslam May 02 '12 at 11:52
  • [self.drawingView release]; [self.windows release]; – Shahid Aslam May 02 '12 at 11:54
  • hmm ok i changed it but still the same result. frustrating -.- – Hashmat Khalil May 02 '12 at 11:54
  • Plenty of errors, you should have to learn things first and then do some, this will keep you away from Mess – Shahid Aslam May 02 '12 at 12:04
  • as a side note glpaint is apple's code example. i only put it in uiview controllers. so i havent done much except trying to learn. i know the code is way too messy – Hashmat Khalil May 02 '12 at 12:06
  • i just reimplemented the whole project with arc enabled. the same story goes on :D no luck – Hashmat Khalil May 02 '12 at 12:54