Crash presenting modal view controller - iphone

I have this crash. It is similar to other threads, but not the same.
I would like to show a modal view controller first the user goes to a specific view controller. Following the hints, I do that on - (void) viewDidAppear:(BOOL)animated, and apply a delay as I saw it's recommended.
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:#selector(presentMyModal) withObject:nil afterDelay:1];
}
- (void) presentModal{
ModalViewController *modal = [[[ModalViewController alloc] init] autorelease];
[self presentModalViewController:modal animated:YES];
}
Afterwards, ramdomly It crashes. I get this message in console:
<Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-1447.6.4/UIWindowController.m:186
Thu Feb 3 10:00:44 unknown MyApp[1830] <Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempting to begin a modal transition from <UINavigationController: 0x454260> to <ModalViewController: 0x47af00> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed'
*** Call stack at first throw:
(
0 CoreFoundation 0x3759dc7b __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32d9bee8 objc_exception_throw + 40
2 CoreFoundation 0x3759dac3 +[NSException raise:format:arguments:] + 70
3 Foundation 0x351a3e73 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 UIKit 0x359e92a8 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 208
5 UIKit 0x359e8c98 -[UIViewController presentModalViewController:withTransition:] + 2792
6 UIKit 0x35a7b51c -[UIViewController _tryRecursivelyPresentModalViewController:withTransition:] + 116
7 UIKit 0x359e84c0 -[UIViewController presentModalViewController:withTransition:] + 784
8 UIKit 0x359e8060 -[UIViewController presentModalViewController:animated:] + 96
9 MyApp 0x0005d57f -[MyAppViewController presentMyModal] + 58
10 Foundation 0x351724db __NSFireDelayedPerform + 366
11 CoreFoundation 0x37552305 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 16
12 CoreFoundation 0x37551cd9 __CFRunLoopDoTimer + 988
13 CoreFoundation 0x37521a91 __CFRunLoopRun + 1184
14 CoreFoundation 0x3752150b CFRunLoopRunSpecific + 226
15 CoreFoundation 0x37521419 CFRunLoopRunInMode + 60
16 GraphicsServices 0x33e76d24 GSEventRunModal + 196
17 UIKit 0x3591d57c -[UIApplication _run] + 588
18 UIKit 0x3591a558 UIApplicationMain + 972
19 MyApp 0x0000e75f main + 50
20 MyApp 0x0000e6e8 start + 52
As you can see, I wait until view is appeared. Is this maybe an OS bug? It seems like it tries to present recursively other modal view controllers, provoquing crashes.
Thanks a lot.

Apart from me being picky in the comment, I thought I could as well help with this one as well. I think you need to search for the culprit somewhere else. I created a new project and a view controller with this snippet:
#import "VC1.h"
#implementation VC1
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self performSelector:#selector(presentModal) withObject:nil afterDelay:1.0];
}
- (void)presentModal {
static int colorChooser = 0;
VC1 *vc1 = [[[VC1 alloc] init] autorelease];
switch (colorChooser%2) {
case 0:
vc1.view.backgroundColor = [UIColor whiteColor];
break;
default:
vc1.view.backgroundColor = [UIColor blackColor];
break;
}
colorChooser++;
[self presentModalViewController:vc1 animated:YES];
}
#end
And it works flawlessly after being pushed on the navigation controller. It is recursively alternating between black and white views, tested both in the sim and on a 3G device.
Maybe you are doing some other view transitions due to some notifications or other asynchronic means? Either way you would need to share more of your code for anyone to tell where the problem is.

Our preferred solution is to use -[UIViewController presentViewController:animated:completion:] and do whatever the next action is (eg presenting another VC) in the completion block.
For example:
[self presentViewController:yourViewController animated:YES completion:^{
[yourViewController presentMyModal];
}];
This method was introduced in iOS 5.0.

Related

iOS crash: respondsToSelector: message sent to deallocated instance

I am using a UINavigationController as rootviewController and storyboard segue for pushingViewController. I have many viewcontrollers in my app. I pass them using push view controller only.
Crash scenario: (can reproduce)
I have a Products list viewController and I will navigate to products detail viewController when I tap on product in the list using tap Gesture recognizer.
From the detail view controller, I will be pushed to cart item viewController which displays all selected products when I tap a button named 'Addd to cart'.
If I try to pay for all the products I want to choose a contact from the people picker, when I press pay button, it will present peopelpickerController as modalViewController and when I choose a contact it gets crashed.
Crash occurs only when move to and fro from products list view controlelr to peoplepicker contoller. When I debugged using instrument I got crash saying deallocated instance receiving message.
I have included the method where I am getting crash. But i never tried to call the method from any controller.
Code...
//choosing contact and people picker delegate
- (IBAction) chooseContacts: (id) sender {
picker = [
[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentViewController: picker animated: YES completion: nil];
}
#pragma mark - Addressbook delegate methods
- (void) peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController * ) peoplePicker {
[self dismissViewControllerAnimated: YES completion: nil];
}
- (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController * ) peoplePicker
shouldContinueAfterSelectingPerson: (ABRecordRef) person {
[self dismissViewControllerAnimated: YES completion: ^ {
[self displayPerson: person];
}];
return NO;
}
Crash occurs in the below method at the line performSegueWithIdentifier,
#pragma mark- Tap gesture delegates
-(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
{
UIImageView *image = (UIImageView *)sender.view;
if (image.tag < [_productsArray count]) {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
productDetailDictionary = [_productsArray objectAtIndex:image.tag];
NSLog(#"%#",productDetailDictionary);
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
}
NSLog(#"imageView.Tag %ld",(long)image.tag);
}
Crash Log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x39cb11fc __pthread_kill + 8
1 libsystem_pthread.dylib 0x39d1aa2e pthread_kill + 54
2 libsystem_c.dylib 0x39c61ff8 abort + 72
3 libc++abi.dylib 0x38f90cd2 abort_message + 70
4 libc++abi.dylib 0x38fa96e0 default_terminate_handler() + 248
5 libobjc.A.dylib 0x396f291e _objc_terminate() + 190
6 libc++abi.dylib 0x38fa71c4 std::__terminate(void (*)()) + 76
7 libc++abi.dylib 0x38fa6a18 __cxa_throw + 112
8 libobjc.A.dylib 0x396f277e objc_exception_throw + 246
9 CoreFoundation 0x2ef5be88 +[NSException raise:format:] + 100
10 UIKit 0x317b9590 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 496
11 UIKit 0x317b7dce -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2054
12 UIKit 0x317b6e20 -[UIViewController presentViewController:withTransition:completion:] + 4664
13 UIKit 0x31992cae -[UIViewController presentModalViewController:animated:] + 26
14 DHCC Events 0x0008f0c0 0x38000 + 356544
15 libdispatch.dylib 0x39bd5d18 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x39bdbd16 _dispatch_after_timer_callback$VARIANT$mp + 46
17 libdispatch.dylib 0x39bd5d04 _dispatch_client_callout + 20
18 libdispatch.dylib 0x39bde7fe _dispatch_source_invoke$VARIANT$mp + 258
19 libdispatch.dylib 0x39bdc73a _dispatch_main_queue_callback_4CF$VARIANT$mp + 186
20 CoreFoundation 0x2ef26814 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
21 CoreFoundation 0x2ef250e8 __CFRunLoopRun + 1296
22 CoreFoundation 0x2ee8fc22 CFRunLoopRunSpecific + 518
23 CoreFoundation 0x2ee8fa06 CFRunLoopRunInMode + 102
24 GraphicsServices 0x33b8327e GSEventRunModal + 134
25 UIKit 0x31733044 UIApplicationMain + 1132
26 DHCC Events 0x00041ad6 0x38000 + 39638
27 libdyld.dylib 0x39bfaab4 start + 0
Appreciate your help.
On -(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
you perform the segue with
[self performSegueWithIdentifier:#"productDetailSeague" sender:sender];
but I think the sender should be self and not sender..
UPDATE
Do you try to perform segue while picker is active? In this case self may be deallocated, so you can try to perform segue after picker is dismissed:
[picker dismissViewControllerAnimated:YES completion:^{[self performSegueWithIdentifier:#"productDetailSeague" sender:self];}];

iPhone App crashes after localization of xib file

I am creating my first iPhone app in which the first screen displays a table view the user selects from. It works before localization using the method below.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:[NSBundle mainBundle]];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
//self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
After I localized it by adding the Japanese localization file and changing the above to this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];
if(self.selectCategoryViewController == nil)
{
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
NSLog(#"the localized bundle is %#",myLocalizedBundle);
SelectCategoryViewController *viewTwo=[[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
self.selectCategoryViewController = viewTwo;
[viewTwo release];
}
[self.navigationController setNavigationBarHidden:YES];//this will hide the navigation bar
[self.navigationController pushViewController:self.selectCategoryViewController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
it crashes with the following error:
√sh.app> (loaded)
2013-02-18 18:04:35.196 PictureEnglish[5529:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString substringFromIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x012775a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x013cb313 objc_exception_throw + 44
2 CoreFoundation 0x0122fef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x0122fe6a +[NSException raise:format:] + 58
4 Foundation 0x00033086 -[NSString substringFromIndex:] + 133
5 PictureEnglish 0x00008524 -[SelectCategoryViewController viewDidLoad] + 937
6 UIKit 0x00378089 -[UIViewController view] + 179
7 UIKit 0x00376482 -[UIViewController contentScrollView] + 42
8 UIKit 0x00386f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
9 UIKit 0x00385555 -[UINavigationController _layoutViewController:] + 43
10 UIKit 0x00386870 -[UINavigationController _startTransition:fromViewController:toViewController:] + 524
11 UIKit 0x0038132a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
12 UIKit 0x0049c2e9 -[UILayoutContainerView layoutSubviews] + 226
13 QuartzCore 0x010a7a5a -[CALayer layoutSublayers] + 181
14 QuartzCore 0x010a9ddc CALayerLayoutIfNeeded + 220
15 QuartzCore 0x0104f0b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
16 QuartzCore 0x01050294 _ZN2CA11Transaction6commitEv + 292
17 UIKit 0x002ca9c9 -[UIApplication _reportAppLaunchFinished] + 39
18 UIKit 0x002cae83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
19 UIKit 0x002d5617 -[UIApplication handleEvent:withNewEvent:] + 1533
20 UIKit 0x002cdabf -[UIApplication sendEvent:] + 71
21 UIKit 0x002d2f2e _UIApplicationHandleEvent + 7576
22 GraphicsServices 0x01bcf992 PurpleEventCallback + 1550
23 CoreFoundation 0x01258944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
24 CoreFoundation 0x011b8cf7 __CFRunLoopDoSource1 + 215
25 CoreFoundation 0x011b5f83 __CFRunLoopRun + 979
26 CoreFoundation 0x011b5840 CFRunLoopRunSpecific + 208
27 CoreFoundation 0x011b5761 CFRunLoopRunInMode + 97
28 UIKit 0x002ca7d2 -[UIApplication _run] + 623
29 UIKit 0x002d6c93 UIApplicationMain + 1160
30 PictureEnglish 0x00001cec main + 102
31 PictureEnglish 0x00001c7d start + 53
32 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Any suggestions on how I should call the SelectCategoryViewController for the selected language?
This line looks wrong to me:
NSBundle *myLocalizedBundle=[NSBundle bundleWithPath:[NSString stringWithFormat:[[NSBundle mainBundle]bundlePath],"en.lproj"]];
You probably meant something like this:
NSString* path= [[NSBundle mainBundle] pathForResource:#"en" ofType:#"lproj"];
NSBundle* bundle:myLocalizedBundle = [NSBundle bundleWithPath:path];
SelectCategoryViewController *viewTwo = [[SelectCategoryViewController alloc] initWithNibName:#"SelectCategoryViewController" bundle:myLocalizedBundle];
This is discussed more here: Manually loading a different localized nib in iOs
Note that this is only required if you want to do an in-app language selection. Localization should typically use the iOS device's selected language, in which case all this is much more straightforward (you simply let iOS pick the bundle for you).
xcode 5:
i had to clean build, clean build folder,delete derived data, reset simulator, close simulator, close Xcode.
Open project again and it's working.
Problem - This is a problem of project path, I think [self.window makeWindowKeyVisible] can not be able to find a path to your first assigned controller...
Solution - It happens some time, when your project suddenly stopped work, So no worries - just shift your project to other path, or just change the name of folder where actually your project resides and it will started working fine....
It works for me successfully...

iOS5 to iOS4 crash - ViewControllers

Currently I am trying to make my app available for iOS4, to increase the number of people we can reach.
We have moved away from StoryBoard and are now using .xib files instead.
Right now, the only thing that is stopping this is this error:
2012-09-14 18:32:42.705 CrunchCalculator[7037:11303] -[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230
2012-09-14 18:32:42.707 CrunchCalculator[7037:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryViewController presentViewController:animated:completion:]: unrecognized selector sent to instance 0x6b42230'
*** Call stack at first throw:
(
0 CoreFoundation 0x013625a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00ef1313 objc_exception_throw + 44
2 CoreFoundation 0x013640bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x012d3966 ___forwarding___ + 966
4 CoreFoundation 0x012d3522 _CF_forwarding_prep_0 + 50
5 CrunchCalculator 0x0002e560 +[OpenCalcViewController openCalcView:fromViewController:] + 8256
6 CrunchCalculator 0x0002fe0a -[CategoryViewController openCalc:] + 106
7 UIKit 0x002554fd -[UIApplication sendAction:to:from:forEvent:] + 119
8 UIKit 0x002e5799 -[UIControl sendAction:to:forEvent:] + 67
9 UIKit 0x002e7c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
10 UIKit 0x002e67d8 -[UIControl touchesEnded:withEvent:] + 458
11 UIKit 0x004e84de _UIGestureRecognizerSortAndSendDelayedTouches + 3609
12 UIKit 0x004e8c53 _UIGestureRecognizerUpdateObserver + 927
13 CoreFoundation 0x0134389b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
14 CoreFoundation 0x012d86e7 __CFRunLoopDoObservers + 295
15 CoreFoundation 0x012a11d7 __CFRunLoopRun + 1575
16 CoreFoundation 0x012a0840 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x012a0761 CFRunLoopRunInMode + 97
18 GraphicsServices 0x014b61c4 GSEventRunModal + 217
19 GraphicsServices 0x014b6289 GSEventRun + 115
20 UIKit 0x00263c93 UIApplicationMain + 1160
21 CrunchCalculator 0x0000276a main + 170
22 CrunchCalculator 0x000026b5 start + 53
)
terminate called throwing an exception(lldb)
Usually I use this to open another view:
UIViewController *controller;
controller = [[CategoryViewController alloc]initWithNibName:#"CategoryViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
[controller release];
But in this case I call a function from a different file (for efficiency) using this code:
#import "AllofTheFiles.h"
+ (void)openCalcView: (NSString *)nameOfView fromViewController:(UIViewController *)controller {
NSUserDefaults *saveSpot = [NSUserDefaults standardUserDefaults];
UIViewController *modalController;
if ([nameOfView isEqualToString:#"Tax"]) {
modalController= [[TAXViewController alloc]initWithNibName:#"TAXViewController" bundle:nil];
}else if ([nameOfView isEqualToString:#"Rent"]){
modalController= [[RENTViewController alloc]initWithNibName:#"RENTViewController" bundle:nil];
} //... cut other else if's to save space
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller presentViewController:modalController animated:YES completion:nil];
[modalController release];
}
How can I fix this? Thanks in advance!
presentViewController:animated:completion: is available on iOS5 and above only, hence you get that crash.
Change the last part to:
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//do we support the new way of presenting a modal viewController?
if ([controller respondsToSelector:#selector(presentViewController:animated:completion:)])
{ //yes->so do it!
[controller presentViewController:modalController animated:YES completion:NULL];
}
else
{ //nope->we seem to be running on something prior to iOS5, do it the old way!
[controller presentModalViewController:modalController animated:YES];
}
[modalController release];
This will first check if the new way of presenting a viewController is supported. For making sure that this works fine in the future, as presentModalViewController: is marked as being deprecated, we only use that option if the new way is not available.
You may need to present a navcontroller, and/or use presentModalViewController, try the following:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:modalController];
navController.modalPresentationStyle = UIModalPresentationPageSheet;
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[controller presentModalViewController:navController animated:YES completion:nil];
[modalController release];
[navController release];
The Till's solution is far the best.
But if, like me, you have numbers of present/DismissModalViewController: calls in your code, and doesn't want to duplicate the respondsToSelector test and is deprecated warnings over and over, just make UIViewController addition:
#implementation UIViewController (iOS4Compatibility)
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag {
if([self respondsToSelector:#selector(presentViewController:animated:completion:)])
[self presentViewController:viewControllerToPresent animated:flag completion:nil];
else
[self presentModalViewController:viewControllerToPresent animated:flag];
}
- (void)dismissViewControllerAnimated:(BOOL)flag {
if([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
[self dismissViewControllerAnimated:flag completion:nil];
else
[self dismissModalViewControllerAnimated:flag];
}
#end

Adwhirl integration problem in iphone

I have two controllers in my application navigation controller and tabbar controller. Navigation controller view does not implement adwhirl and tabbar controller all tabs all view has adwhirl implemented.
#interface myview : UIViewController {
AdWhirlView *awView;
}
#property (nonatomic, retain) AdWhirlView *awView;
#implementation myview
#synthesize awView;
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
- (NSString *)adWhirlApplicationKey {
return #"Mykey";
}
-(void) viewWillAppear:(BOOL)animated{
// code for Adwhirl banner
self.awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
[self.awView setFrame:CGRectMake(0, 318, 320, 50)];
[self.view addSubview:self.awView];
}
-(void) viewWillDisappear:(BOOL)animated{
[self.awView release];
}
I have write this code in each view in tabbar controller. Adwhirl is perfectly work when i shift navigation controller to tabbar controller. But application is crashed when i shift tabbar controller to navigation controller.
The crash error is as follow.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray viewControllerForPresentingModalView]: unrecognized selector sent to instance 0xfd91600'
*** Call stack at first throw:
(
0 CoreFoundation 0x018525a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x019a6313 objc_exception_throw + 44
2 CoreFoundation 0x018540bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x017c3966 ___forwarding___ + 966
4 CoreFoundation 0x017c3522 _CF_forwarding_prep_0 + 50
5 IDogEvents 0x0002e30b -[AdWhirlAdapterGoogleAdMobAds getAd] + 2075
6 IDogEvents 0x00040154 -[AdWhirlView makeAdRequest:] + 1524
7 IDogEvents 0x0003f501 -[AdWhirlView buildPrioritizedAdNetCfgsAndMakeRequest] + 1569
8 IDogEvents 0x000402ef -[AdWhirlView timerRequestFreshAd] + 255
9 Foundation 0x0095b749 __NSFireTimer + 125
10 CoreFoundation 0x018338c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
11 CoreFoundation 0x01834e74 __CFRunLoopDoTimer + 1220
12 CoreFoundation 0x017912c9 __CFRunLoopRun + 1817
13 CoreFoundation 0x01790840 CFRunLoopRunSpecific + 208
14 CoreFoundation 0x01790761 CFRunLoopRunInMode + 97
15 GraphicsServices 0x01a8a1c4 GSEventRunModal + 217
16 GraphicsServices 0x01a8a289 GSEventRun + 115
17 UIKit 0x001cbc93 UIApplicationMain + 1160
18 IDogEvents 0x00002349 main + 121
19 IDogEvents 0x000022c5 start + 53
20 ??? 0x00000001 0x0 + 1
Please help me for this.Thanks in advance.
I got the solution.
I made common object for
AdWhirlView *awView;
in application delegate.
In every view i am using this object instead of self class object.
-(void) viewWillAppear:(BOOL)animated{
// code for Adwhirl banner
appDelegate.awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
[appDelegate.awView setFrame:CGRectMake(0, 318, 320, 50)];
[self.view addSubview:appDelegate.awView];
}
-(void) viewWillDisappear:(BOOL)animated{
[appDelegate.awView removeFromSuperview];
}
And in final view where i shift the controller.
-(void) viewWillDisappear:(BOOL)animated{
[appDelegate.awView removeFromSuperview];
[appDelegate.awView release];
}

release view controller and removing view

Quick question:
If I use
[someViewController.view addSubView:otherViewController.view];
to add a view. And then use
[otherViewController.view removeFromSuperView]
to remove the view, my app will crash when I call [otherViewController release]
The crash point is in the [super dealloc] line in my dealloc method of otherViewControll class implementation.
otherViewController is a reference to the view controller. I call release after its view has been removeFromSuperView'ed. By the time I call release, it's a valid pointer.
What am I doing wrong here?
otherViewController's dealloc class implementation
- (void)dealloc {
[popVC release];
[photoContainer release];
[photoView release];
[recordName release];
[recordIngr release];
[recordDesc release];
[recordPrice release];
[quantity release];
[pricingLabel release];
[increaseButton release];
[decreaseButton release];
[pricingTableVC release];
[pricingTable release];
[super dealloc]; // <--- crash point
}
updated: call trace
2011-06-04 00:35:05.110 MyApp[2308:207] -[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0
2011-06-04 00:35:05.124 MyApp[2308:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType _viewDelegate]: unrecognized selector sent to instance 0x4b6feb0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dd75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f2b313 objc_exception_throw + 44
2 CoreFoundation 0x00dd90bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d48966 ___forwarding___ + 966
4 CoreFoundation 0x00d48522 _CF_forwarding_prep_0 + 50
5 UIKit 0x00379051 -[UIViewController dealloc] + 128
6 MyApp 0x00009b26 -[RecordDetailViewController dealloc] + 797
7 MyApp 0x00004744 __-[RecordRootViewController bringUpNextRecordDetail:isNext:]_block_invoke_2 + 77
8 UIKit 0x002f7fb9 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 294
9 UIKit 0x002f7e4b -[UIViewAnimationState animationDidStop:finished:] + 77
10 QuartzCore 0x01d7b99b _ZL23run_animation_callbacksdPv + 278
11 QuartzCore 0x01d20651 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
12 CoreFoundation 0x00db88c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
13 CoreFoundation 0x00db9e74 __CFRunLoopDoTimer + 1220
14 CoreFoundation 0x00d162c9 __CFRunLoopRun + 1817
15 CoreFoundation 0x00d15840 CFRunLoopRunSpecific + 208
16 CoreFoundation 0x00d15761 CFRunLoopRunInMode + 97
17 GraphicsServices 0x0172e1c4 GSEventRunModal + 217
18 GraphicsServices 0x0172e289 GSEventRun + 115
19 UIKit 0x002d5c93 UIApplicationMain + 1160
20 MyApp 0x0000200c main + 102
21 MyApp 0x00001f9d start + 53
)
terminate called after throwing an instance of 'NSException'
Update:
in -viewDidLoad, I have a gesture recognizer:
{
UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(showNextRecod:)];
[leftSwipeGestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:leftSwipeGestureRecognizer];
[leftSwipeGestureRecognizer release];
}
I tried to use a Button to call -(IBAction) showNextRecod, it won't crash!! Only when I use the gesture to call the same method, it would crash
Regards
Leo
When you add a view controller's view as a subview to another view, you are only retaining it's view in memory and not the controller itself. Therefore, you must retain the view controller somewhere else (most likely make it a property)
Does that make sense?
In your gesture selector showNextRecod:
you should remove your target [pGestureRecognizer removeTarget:nil action:NULL];
#leo
You are just adding otherViewController.view in someViewController.view.
Just adding view not allocating it, then just remove it from your view.
Im not getting why you are using
[otherViewController release]
when you are not allocating it same view.
For sure you can log otherViewController.view count. See how much retain count for that view you are getting.