I am experiencing a crash on my app when the following code is executed:
- (void)presentSearchViewController
{
if(!_searchController)
{
SearchStickerViewController *searchController = [[SearchStickerViewController alloc] initWithNibName:#"SearchStickerViewController" bundle:nil];
searchController.delegate = self;
[searchController.view setFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
_searchController = searchController;
}
[self addChildViewController:_searchController];
[self.view addSubview:_searchController.view];
[_searchController didMoveToParentViewController:self];
}
The strange thing is that I am using the same code to push other ViewControllers I have and it works just fine. It doesn't crash always, it starts crashing after I go back and forth for around the 5th time (maybe it crashes on the 6th or 7th).
The error I get is:
Terminating app due to uncaught exception
UIViewControllerHierarchyInconsistency', reason: 'child view
controller:< UICompatibilityInputViewController: 0x1004e6af0> should
have parent view controller:< CKFullScreenAppViewController:
0x104e458f0> but actual parent is < UIInputWindowController:
0x100830200>
The code I am using to dismiss the ViewController is:
- (void)dismissSearchResultsViewController
{
[_searchController willMoveToParentViewController:nil];
[_searchController.view removeFromSuperview];
[_searchController removeFromParentViewController];
}
Any ideas on how to troubleshoot/fix this?
Related
I have a collection view inside self-sizing tableview. When user tap on collection view, I present another view.
I can still present that view in portrait orientation. But when I rotate to landscape, I got this error and crash. How shall I do?
2017-01-23 16:52:16.448417 SWEET Mini[1638:647130] * Assertion
failure in -[_UIFlowLayoutSection
computeLayoutInRect:forSection:invalidating:invalidationContext:],
/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.6.22/UIFlowLayoutSupport.m:823
2017-01-23 16:52:16.451537 SWEET Mini[1638:647130] * Terminating app
due to uncaught exception 'NSInternalInconsistencyException', reason:
'UICollectionViewFlowLayout internal error'
I just present another view like this.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.zoomPhotosToFill = NO;
[browser setCurrentPhotoIndex:(indexPath.row)];
browser.enableSwipeToDismiss = YES;
UINavigationController *browseNav = [[UINavigationController alloc] initWithRootViewController:browser];
if ([[AppDelegate instance].window.rootViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *nav = (UINavigationController *) [AppDelegate instance].window.rootViewController;
[nav presentViewController:browseNav animated:YES completion:nil];
}
else if ([[AppDelegate instance].window.rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tab = (UITabBarController *) [AppDelegate instance].window.rootViewController;
[tab presentViewController:browseNav animated:YES completion:nil];
}
}
I had the same issue with the same error message. Turns out, it's only happening on the simulator, everything works fine on real device.
I am trying to move my indexPath.row to a different viewcontroller - pageView label. This is what I have tried:
[cell.nav addTarget:self action:#selector(naviguate:) forControlEvents:UIControlEventTouchUpInside];
cell.nav.tag=indexPath.row;
-(void)naviguate:(id)sender {
UIButton *theButton=(UIButton *)sender;
NSLog(names[theButton.tag]);
pageView *secondViewController = [[pageView alloc] initWithNibName:#"secondViewController" bundle:nil];
secondViewController.name.text = names[theButton.tag];
}
Why is this not changing the label text on pageView. How should I do it?
Where the Logs string works fine.
Edit for #danh
I have tried this:
-(void)naviguate:(id)sender {
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
[_tableView setFrame:CGRectMake(0, 569, _tableView.frame.size.width, _tableView.frame.size.height)];
}
completion:^(BOOL finished){
[self performSegueWithIdentifier:#"link" sender:self];
}];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIButton *theButton=(UIButton *)sender;
if([segue.identifier isEqualToString:#"link"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
pageView *controller = (pageView *)navController.topViewController;
controller.name.text= names[theButton.tag];
}
}
where it is being called by
[cell.nav addTarget:self action:#selector(naviguate:) forControlEvents:UIControlEventTouchUpInside];
cell.nav.tag=indexPath.row;
But I am getting the error [pageView topViewController]: unrecognized selector sent to instance ... Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[pageView topViewController]: unrecognized selector sent to instance
Do you know why?
2nd attempt
with:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIButton *theButton=(UIButton *)sender;
if([segue.identifier isEqualToString:#"link"])
{
pageView *controller = (pageView *)segue.destinationViewController;
controller.name.text= names[theButton.tag];
}
}
I get the error '-[ImagesTableViewController tag]: unrecognized selector sent to instance
WHich is crashing because of names[theButton.tag] How come?
This line:
pageView *secondViewController = [[pageView alloc] initWithNibName:#"secondViewController" bundle:nil];
creates a new view controller, then this line:
secondViewController.name.text = names[theButton.tag];
sets one of it's view's properties (which is wrong, because the view isn't loaded yet, and because it's ill-advised to mess around with another vc's views). But that doesn't really matter, because this line:
}
destroys the newly allocated vc, which will never be heard from again.
The way to fix is either to use a segue from the starting view controller, and set properties of the destination in prepareForSegue:, or to push or present the secondViewController. Either:
// if we're in a navigation controller
[self.navigationController pushViewController:secondViewController animated:true];
// or, if there's no container
[self presentViewController:secondViewController animated:true completion:nil];
Remember, no matter how you decide to present secondViewController, don't try to set the state of one of it's subviews directly. Instead, give it a property like NSString *theStringMyLabelShouldShow, and set that from the presenting vc. The second VC can mess with it's own views in viewWillAppear:
self.name.text = self.theStringMyLabelShouldShow;
I am facing crash with following code. The scenario is
This is my app delegate method in which i load RTC_HomeVC using UINavigationController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
RTC_HomeVC *obj_RTC_HomeVC=[[RTC_HomeVC alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:obj_RTC_HomeVC];
// Override point for customization after application launch.
self.window.rootViewController=nav;
[obj_RTC_HomeVC release];
[nav release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Now I want to open UINavigationController inside a parent Navigation controller. So i use a following code. The method -(IBAction)call_SectionFlow is in RTC_HomeVC.
-(IBAction)call_SectionFlow{
RTC_1_StoreDetailsVC *obj_StoreDetailsVC=[[RTC_1_StoreDetailsVC alloc]initWithNibName:#"RTC_1_StoreDetailsVC" bundle:nil];
RTC_3_EnablingWorksVC *obj_EnablingWorksVC = [[RTC_3_EnablingWorksVC alloc]initWithNibName:#"RTC_3_EnablingWorksVC" bundle:nil];
UINavigationController *navController_Sections = [[UINavigationController alloc] init];
NSArray *array_ControllerArray=[[NSArray alloc]initWithObjects:obj_StoreDetailsVC,obj_EnablingWorksVC, nil];
[navController_Sections setViewControllers:array_ControllerArray animated:FALSE]
navController_Sections.view.frame=CGRectMake(14, 40, 996,636 );
[self.view addSubview:[[[navController_Sections viewControllers] objectAtIndex:0] view]];
}
When i called this method application is crashed. This is crash log.
Crash log:
* Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:< RTC_1_StoreDetailsVC: 0x71f53a0 > should have parent view controller:< RTC_HomeVC: 0x758b310 > but actual parent is:< UINavigationController: 0x71f55d0 >'
* First throw call stack:
(0x1c9c012 0x10d9e7e 0x1c9bdeb 0x6838a 0x68739 0x6f5a3 0x67eed 0x4fc3 0x10ed705 0x24920 0x248b8 0xe5671 0xe5bcf 0xe4d38 0x5433f 0x54552 0x323aa 0x23cf8 0x1bf7df9 0x1bf7ad0 0x1c11bf5 0x1c11962 0x1c42bb6 0x1c41f44 0x1c41e1b 0x1bf67e3 0x1bf6668 0x2165c 0x1f82 0x1c45)
libc++abi.dylib: terminate called throwing an exception
So any one can tell me
What is wrong with this code? And which approach i should follow for resolving this crash ?
How to open another UINavigationController in existing UINavigationController?
Thanks.
Do not add subviews to UIWindow manually. It is not supported (or at least it does not work OK).
Use this method:
[firstNavigationVC presentViewController:secondNavigationVC animated:YES completion:nil];
What is causing crash is, that you are adding obj_StoreDetailsVC to the new navigation controller and then its view to self.view. Once a VC is child of another VC, its view must be descendant of that VC's view. Maybe you can add secondNavigationVC's view to to the view of firstNavigationVC, but that isn't how UIKit is supposed to work. Use the above method.
I have an app that uses a transition file to flip from page to page. I am using ARC and works just fine on 5.1, but crashes all the time on 4.3 simulator. Looking at the thread and the extended detail from instruments, it points to 2 lines of code (shown below) with the error: EXC_BREAKPOINT (code=EXC_I386_BPT). Looks like the UIViewController is being deallocated. Not sure how to fix this. Thanks in advance for any help you can offer!
#synthesize containerView = _containerView;
#synthesize viewController = _viewController; //ERROR LINE#1
- (id)initWithViewController:(UIViewController *)viewController
{
if (self = [super init])
{
_viewController = viewController;
}
return self;
}
- (void)loadView
{
self.wantsFullScreenLayout = YES;
UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.view = view;
_containerView = [[UIView alloc] initWithFrame:view.bounds];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
[_containerView addSubview:self.viewController.view];
}
- (void)transitionToViewController:(UIViewController *)aViewController
withOptions:(UIViewAnimationOptions)options
{
aViewController.view.frame = self.containerView.bounds;
[UIView transitionWithView:self.containerView
duration:0.65f
options:options
animations:^{ [self.viewController.view removeFromSuperview];
[self.containerView addSubview:aViewController.view];}
completion:^(BOOL finished)
//ERROR LINE#2 { self.viewController = aViewController;}];
}
You should not be transitioning views in and out from underneath their respective view controllers. You might get it to work, but it's fragile, at best.
If you want to future-proof your code, you should be transitioning between view controllers and let them handle their own views, but wrap that in the desired animation if you don't like the default animation. So, you should either:
Just do simple presentViewController or pushViewController to go to the next controller and dismissViewController or popViewController to return; or
In iOS 5, you can do your own container view controller (see session 102 in WWDC 2011 or see the discussion of view controller containment in the UIViewController reference) and then you can transitionFromViewController.
If we knew more about your app flow, why you're doing what you're doing, we can probably advise you further.
I support portrait only ATM, I get these error when rotating the device:
[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData setProperRotation]: unrecognized selector sent to instance 0x2dc890'
This is in iOS5.1. Initially I just left the default portrait clause in, but changed it to:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait) { // Or whatever orientation it will be presented in.
return YES;
}
return NO;
}
I am using ARC btw.
Hoping that would help stop the crashing. My info.plist has portrait and portrait upside down. There is nothing else I have done thats stock practice except my main view has multiple ViewControllers and its set to:
self.wantsFullScreenLayout=YES;
Any ideas peoples? Thanks in advance.
My project adds the main view from the appdelegate as such:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
mainViewController=[[MainViewController alloc] init];
[self.window addSubview:mainViewController.view];
And I have 2 ViewControllers on that mainViewController and I use a Navigation controller to push several ViewControllers as such:
- (void) loadActionsView {
NSArray* views = [self.navigationController viewControllers];
if ([views containsObject: actionsPanelViewController])
{
[self.navigationController popToViewController:actionsPanelViewController animated:YES];
} else {
[self.navigationController pushViewController:actionsPanelViewController animated:YES];
}
[[StateModel stateModel] setCurrentScreenIndex:0];
}
This is the first view that is called btw.
Update 2 with Solution/problem found:
I was using part of SHK the SHKActivityIndicator, that had a notification that was capturing the screen rotation and its selectors where causing the issue:
[[NSNotificationCenter defaultCenter] addObserver:currentIndicator selector:#selector(setProperRotation) name:UIDeviceOrientationDidChangeNotification object:nil];
It sounds like your ViewController is released and another Object receives setProperRotation message. Check if your ViewController is alive.
mainViewController=[[MainViewController alloc] init];
[self.window addSubview:mainViewController.view];
here is the problem. You adding only the view. ARC thinks that you dont need your MainViewController anymore.
Make MainViewController as a Class variable or
set window.rootViewController
self.window.rootViewController = mainViewController;
The exception shows that you are likely over-releasing an object which is supposed to responds to -setProperRotation. Look for that object and try to understand where you forgot to retain it (for example, track its retains and releases with Object allocation instrument)