Modal View not being removed from stack - iphone

I am creating a modal view which is opened using the following code
[[self navigationController] presentModalViewController:registrationController animated:NO];
And until recently the following code was used to hide it on a button press
[self dismissModalViewControllerAnimated:YES];
However for some reason that line is no longer removing the view and no errors are presented.
I have also tried
[self.view removeFromSuperView];
But that just leaves me with a completely white screen
Any suggestions on how I go about debugging this issue will be great as Im stumped

Assuming your controller is a subclass of UIViewController, then inside the modal view controller:
[self.parentViewController dismissModalViewControllerAnimated:YES];

I worked out the problem I was updating the Navigation Controller after loading the modal in order to change the style, changing the order solved the problem

Related

UISearchDisplayController's table view separator lines glitch when loading inside a modal view, how do I fix it?

I'm trying to load a basic search view overlaying my navigation controller (that is, not pushed on the navigation stack). To achieve this I'm using [self presentModalViewController:vc animated:NO].
Full modal view presentation code:
- (void)searchButtonPressed
{
TMSearchViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Search"];
[self presentModalViewController:vc animated:NO];
vc.searchDisplayController.searchBar.delegate = self;
}
After the modal view is presented on the screen, the following code—inside the search view's controller—is run:
- (void)viewDidAppear:(BOOL)animated
{
[self.searchDisplayController.searchBar becomeFirstResponder];
[self.searchDisplayController setActive:YES animated:NO];
}
The problem is that when the search view renders, it does the normal thing where it blacks out the table view with a transparent black view, but it doesn't appear to cover the table view's separators, which looks like this:
I really have no idea how to fix it. My best guess is that it is something to do with the modal controller's process of loading a view that I'm not understanding properly. I've tried moving the becomeFirstResponder to the viewDidLoad method. I've also tried reordering the setActive method and the becomeFirstResponder method whilst changing the setActive method to animated:NO and YES.
So far, no avail, I'm clearly not understanding something here and I'm guessing I'm using something in a way that is unintended. Please help, Thanks :)
edit: interestingly enough, when I click the blacked out table view to resignFirstResponder the searchbar, and then click inside the searchbar again to activate becomeFirstResponder it loads fine, without the glitch, how it's meant to.
Did you try self.searchDisplayController.searchResultsTableView.separatorStyle=UITableViewCellSeparatorStyleNone; ??
Okay so after hours of messing around in the code, trying to understand what I'd done wrong, I've finally found the answer, or at least a fix. (I'm still mystified as to what was actually going wrong)
I simply deleted the searchbar from the interface builder in storyboard. And replaced it with another one—which involved reconnecting the searchbar to be the searchDisplayController's searchbar property, of course.
My best guess is that Xcode for whatever reason didn't like the order in which I dragged in and connected the UI elements to interface builder/storyboard.
Hope this helps someone.

black bar as the view fades when I am using navigation controller

I'm writing my first iPhone app and I am trying to figure out how to have a MasterView and DetailsView like in the example. However, instead of using a TableView, I want to use a button on the MasterView to go to the SignUpView. I want the MasterView to NOT have a navigation bar but the SignUpView needs to have one.
I have tried putting a NavigationController into the MasterView using the interface builder. This doesn't seem to do anything at all ... I.e. I make the following call:
[self.navigationController pushViewController:signUpViewController animated:YES];
And nothing happens. The SignUpView is never shown.
So then I declared a NavigationController in the AppDelegate. The above call in the same function that it was in before (button handler, button is in MasterView) works now! It takes me to the SignUpViewController.
however, the issue is, when I press back on the navigation bar in the sign up view, the navigation bar shows up again in the MasterView. I tried to set
self.navigationController.navigationBarHidden = YES;
in viewDidLoad and viewDidAppear, but that causes a black bar to appear in the transition from SignUpView to MasterView.
I tried to not set it in one of the two, and that causes the animation to go smoothly, but the navigation bar shows up in the MasterView.
I feel like this should be pretty simple to do ... but I'm at my wits end trying to figure this out. Some help would be really appreciated!
Thanks.
Probably not the answer to your question, but just a small suggestion. In the many apps that I have come across, a sign-up/sign-in view is generally displayed as a modal view (on top of your master view) with a 'cross' in the top-right corner to dismiss it. Probably it results in a better user experience.
Also, did you try self.navigationController.navigationBarHidden = YES; in the MasterView's viewWillAppear ?
HTH,
Akshay
I had this problem too, until I discovered setNavigationBarHidden. You will probably want to use these in viewWillAppear/viewWillDisappear or viewDidAppear/viewDidDisappear. You don't want to call this in viewDidLoad because that is only called once when the view is initialized, not every time it appears.
To hide:
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show:
[self.navigationController setNavigationBarHidden:NO animated:YES];

Remove a view to show a previous view at a previous point on a scrollview

I'm new to iOS and I have an initial view with a scrollview and a row of buttons. When I press one it opens a new view with a new view controller, no problem. What I'm having a problem with is when I try to return to the initial view the code I was using initializes a new instance of my initial view. How can I return to my initial view at the same point on my scrollview that I pressed the button?
Thanks in advance guys!
if you are using
[self presentModalViewController:viewController];
just use
[self dismissModalViewControllerAnimated:YES];
to dismiss the view.
I'm having trouble visualizing this. A little bit of the code in question would be helpful. Anyways are you using pushViewController:animated: and popViewControllerAnimated: to move back and forth between views?
to change views with button events
[self.navigationController pushViewController:viewController animated:YES];
and to move back a view
[self.navigationController popViewControllerAnimated:YES];
For going to previous view always you should try to not alloc and just dismiss by calling
[self dismissModalViewControllerAnimated:NO];
If u will do alloc every time you may face issue of memory and other things.....

topBar equivalent of hidesBottomBarWhenPushed?

I have a UINavigationController in which the root view doesn't display the top navigation bar via
[[self navigationController] setNavigationBarHidden:YES animated:NO];
The view I'm pushing onto this does need to display the navigation bar, and I'm currently using the above method to show it and then hide it again when the view is popped. This results in some weird going-ons, which I would like not to have going on.
EDIT: To clarify, right now I'm using [[self navigationController] setNavigationBarHidden:NO animated:NO]; in the pushed view, and what's happening is the navigationBar appears in both the outgoing view and the new one, and it looks pretty messy to have that flash happen. Here's what's currently happening:
And What I'd like:
Instead what I would like is for the navigation bar to already be showing while the view is being pushed, and not on the root view, much like the behaviour of the hidesBottomBarWhenPushed property.
Can anyone point me in the right direction here?
What if you put:
[[self navigationController] setNavigationBarHidden:NO animated:NO];
in your pushed view controller's -viewDidLoad method?
I've noticed that the transitions are much smoother (no weird flicker) if you allow them to animate. Switch your animated flag to YES and see if that smooths things out.
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[[self navigationController] setNavigationBarHidden:NO animated:YES];
Also, I uncheck the "Shows Navigation Bar" checkbox in the IB inspector for my navigation controller rather than doing it in code. That way its default state is hidden when thawed from the xib. The code should effectively do the same thing, but it may be worth trying as I don't have the problem you describe when implementing the same thing.
Two comments. I am doing the same thing and I agree that it does seem to work better when animated. Also you should be calling it in viewWillAppear or viewDidAppear. Personally I am using viewDidAppear and animated:YES and think that look pretty good.
Since you are setting a application level setting you need to make sure you call it at the right time to avoid the issues you are seeing.

Presenting ViewController behind another one

I have image picker which collects data for another view controller (TTMessageController from three20) and I want this message composer to appear behind image picker, so when image piker slides out there will be already appeared message controller with pre-filled data.
Code like this
[self.navigationController presentModalViewController:composeController animated:NO];
[picker dismissModalViewControllerAnimated:YES];
and vice-versa wont work at all. What to do? How to present composeController behind already presented picker controller?
Thanks in advance.
Actually removing animation from both viewController help.
[picker dismissModalViewControllerAnimated:NO];
[self presentModalViewController:composeNavController animated:NO]; // If YES it crashes
But it's not to iPhone-ish if get what I mean, even fade throw black or just some visual effect will make it look much, much nicer. Technically tho, it works.
Edit:
Ok I think the problem here is the modal bit, as the iPhone really appears to not like you having 2 views set to modal, or even animating from one modal view to another.
Do they definitely have to be modal? How about adding them to the normal navigation stack?
You could add the message view to the stack first (non-animated) so that it's there when you pop back one.
Try this:
The order in which you add views to the stack affects the order that they will display in when you dismiss them.
This part adds the composeController to the stack and then animates the picker going on top. Use this code to display the picker controller (ie instead of modal dialog):
[self.navigationController pushViewController:composeController animated:NO];
[self.navigationController pushViewController:picker animated:YES];
Then, when you are done with the picker, you can "pop" the view back to the message composer:
[self.navigationController popViewControllerAnimated:YES];
You should now have no references to any modal dialogs remaining in your code. I believe this should work much better than modal, which really is for displaying one view above every other one, not for switching from view to view.
Hope that helps!
Instead of trying to present another viewController behind the picker, you could dismiss the image picker modal view controller, push the Message controller (both with animated:NO), and then use a CATransition to perform your own Cocoa-like animation of the image picker animating off screen.
You need to split these animations up so they don't execute in the same runloop. I've run into a situation where the OS does not like dismissing and presenting modal views back to back.
Try this:
- (void)myCallbackMethod{
[picker dismissModalViewControllerAnimated:YES];
[self performSelector:#selector(presentMessage) withObject:nil afterDelay:0.25];
}
- (void)presentMessage{
[self.navigationController presentModalViewController:composeController animated:YES];
}