How to trigger a pop up window from another pop up window in Objective C - objective-c

I want to open a popup from another popup and I used the below code, but when I click the pop up it moves to a new page instead of showing another popup. is there a way to create a popup effect with navigationController?
[weakself.navigationController pushViewController:deleteVC animated:YES];

Instead of pushing the view controller to the navigation stack, use presentViewController:animated:completion: method to open it modally.
It's important that you send this message to the presenting view controller itself, not to the navigation controller:
[weakself presentViewController:deleteVC animated:YES completion:nil];

Related

Why UINavigationController keep popping out the top controller

I have UITabBarController, one of the tab points to a UINavigationController. The UINavigationController rootViewController is of class BGProfileView which shows users' profile
At viewDidAppear, I arranged that if users didn't logged in it will push a BGLogin view controller.
[BGLogin alreadyLoggedin:self.navigationController hideBackButton:YES anddoBlock:^{
[self whatToDoAfterLogin];
}];
Now everything is fine but with one minor issue. If I press the tab again, BGLogin will be poped out of UINavigationController.
I have no idea what makes that BGLogin poped out.
If I select a different tab and then click back to the BGProfile tab, this doesn't happen. It just happens when I click the same active tab. So I am in BGProfile tab, and I click that tab again. Basically it happens when I select the active tab that should simply do nothing. In fact, it does do nothing on others.
I put a breakpoint in viewWillDisappear and this is what I see:
As you see, viewDidAppear is called by the main loop. But why the hell the mainloop call viewDidAppear? Usually there is a code saying things like nav popViewController
Chances are there . that your tab bar controller is pushing new navigation controller with root view controller. and you interpreting that it's popping out. When same tab is selected you need to tell your tabBarController to not to do anything explicitly.
Example
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
UIViewController *tbSelectedController = self.tabBarController.selectedViewController;
if ([tbSelectedController isEqual:viewController]) {
return NO;
}
return YES;
}

Pushing a navigation controller is not supported- performing segues

I created a new navigation controller in my storyboard (not programmatically!) and set it to be "Root View Controller" to a regular UIViewController and added a button in it which says- forward to the next view controller (this second view controller is a view controller which I want that will have a back button to link to the initial view controller).
Now, whenever I try to link the button to the next view controller- "Pushing a navigation controller is not supported".
Help me please, and thanks
EDIT:
I accidentally subclassed UINavigationController, and not UIViewController in my class.
Thank you anyway.
I've tried this and have no problems, its all done in IB with no additional code required ...
Start a new project, "Single View Application" using story boards
Select storyboard and delete the views its produced.
Drag on a new Navigation Controller (it will bring a table view with it)
Delete the table and the table view controller, so you are just left with the Navigation Controller
Drag on a normal view controller
Right Click and drag from the Navigation controller to the new View and choose "Relationship - Root View Controller"
Drag a "Bar Button Item" on to the Navbar which should be visible on the top of your ViewController, you can rename this Forward if you wish.
Now drag on another view controller which is the one your "Forward" button will push in to view.
Right Click and drag from the bar button to the 2nd View Controller, and choose "Push"
Run the project and you will get a Single view with a Navbar and your button, clicking your button will Push the other view and give you a Back Button to return to the first View Controller. I'll try and post a picture of my storyboard if it helps.
Plasma
I had the same trouble. I wanted to have a navigation controller on each storyboard, so that each could run independently, be individually debugged, and so that the look would be right with the navigation bar.
Using other approaches, I found the UINavigationController would be retained from the original storyboard -- which I didn't want -- or I'd get errors.
Using the AppDelegate in your view controller to set the rootViewController worked for me (borrowing segue naming conventions from Segue to another storyboard?):
- (void)showStartupNavigationController {
NSLog(#"-- Loading storyboard --");
//Get the storyboard from the main bundle.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Startup" bundle:nil];
//The navigation controller, not the view controller, is marked as the initial scene.
UINavigationController *theInitialViewController = [storyBoard instantiateInitialViewController];
NSLog(#"-- Loading storyboard -- Nav controller: %#", theInitialViewController);
//Remove the current navigation controller.
[self.navigationController.view removeFromSuperview];
UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
window.rootViewController = theInitialViewController;
To swap views Programatically you would need to select the segue and give it an Identifier like "PushView" then call it like this ....
[self performSegueWithIdentifier:#"PushView" sender:self];
That will programatically do the same as clicking the forward button. I've created you an example project with the code discussed above. Has an -(IBAction) with code in you can use for programatially changing the view.
PushView.zip
I also wanted to do this, present a screen (that had an embedded navigation controller) when the user pushes a button.
At my first attempt, I connected the segue from the button in the fist screen to the Navigation Controller, and the app was crashing with this error "Pushing a navigation controller is not supported".
This is the solution I found:
Select the segue from the button in the first screen to the navigation controller.
If it had an identifier, copy its name. Then delete that segue.
Then create a new segue by CTRL-clicking the button in the first view controller and dragging to the VIEW CONTROLLER YOU WANT TO PRESENT (not to the Navigation Controller that is pointing at it), and select Push in the small pop up window.
Then click the icon in the middle of the segue and paste the name you copied in the first step as an identifier for it.
IB is going to give you a warning "Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:." Don't worry, it works perfectly.
If you want to customize the string that is shown as the Back button to return, you can add this line in the viewDidLoad method OF THE VIEW CONTROLLER THAT IS BEING SHOWED AFTER THE BUTTON IS PRESSED, that is the Child view controller.
(replace "Settings" with the name you need)
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.topItem.title = #"Settings";
...
}

Mail TabBarItem dismissModalViewControllerAnimated

I'm adding TabBarItem (Email) dynamically. When I finish with my email, I'm calling 'dismissModalViewControllerAnimated' but it's simply dismissing mail view. How do I unload the view controller?
in my email view controller I'm doing following:
- (void)viewDidLoad => I would like to unload this view controller
{
[super viewDidLoad];
[self showEMail:nil]; => this display and dismisses email (I'm not calling present.. and dismiss... in a row. I'm using delegate methods to present and dismiss, which is fine.)
[self presentModalViewController:picker animated:YES];
[self dismissModalViewControllerAnimated:YES];
}
after selecting my tab bar item, it's loading view controller(Lets say 'ABC View controller') which is presenting my mail modal controller. mail modal controller is being dismissed properly. but I would like to come back to previously selected tab item after unloading the 'ABC view controller'. is it possible? or am i doing something wrong here?
Thanks in advance
Rama
Rama, your question is hard to understand. maybe you need to use delegation for the view controller you are presenting.
In your code, calling [self presentModalViewController...] and [self dismissModalViewController...] in a row doesn't make sense.
You shall call the [self presentModalViewController...] in the first place, make the presenting view controller as the delegate (picker.delegate = self, for instance)
let the modal view controller do its business including exiting (like user hits cancel, close or whatever), then call the delegation method (something like [delegate didFinish...] or [delegate didCancel...]
now it's the presenting view controller's turn to response to the delegation method calling, you can do the modal view controller dismissing here
Note: many UIKit classes practice this pattern, such as UIAlertView, UIActionSheetView, MPMoviePlayerViewController, etc. You shall check them and make your own
I've solved problem by using ViewWiilAppear method to display mail modal presenter.
and i'm selecting the index of tab bar controller after dismissing mail modal presenter.
self.tabBarController.selectedIndex =0;
This solved my problem.
Cheers

present new modal view controller then dismiss old modal view controller

i want to dismiss my current view controller then load up a new view controller. this seems like it should work:
FieldReportViewController *fieldReport = [self.storyboard instantiateViewControllerWithIdentifier:#"fieldReportView"];
[self presentModalViewController:fieldReport animated:YES];
[self dismissModalViewControllerAnimated:NO];
i present the new modal, then dimiss the old one. but the old one doesn't actually get dismissed.
any idea how i can get this done or why this won't work?
You are not dismissing the old modal view controller....you are dismissing the new one you just presented. Try dismissing the modal view controller first.
first dismiss the old view before present the nezt one or use the actual names instead of "self"
add this code:
#import "class of the to dismiss view.h"
#class class of the to dismiss view
When you present a modal view controller, depending on which iOS version you're using, you're setting the property modalViewController or presentingViewController of the 1st modal to a second modal and adding the 2nd view controller to the view hierarchy. If you were successful in removing the first modal, the second modal would no longer be attached to any view hierarchy.
What you may want to consider is using a single view controller and just replacing the view for that modal view. I think this would give you what you want.
Alternatively, you should probably dismiss the first modal and from the previous view controller present the second modal.

how to load UITabBarController?

I have a code that currently loads a NIB file like below :
Login *monLogin = [[[Login alloc] init] autorelease];
[self presentModalViewController:monLogin animated:YES];
but the app is TabBar App (xcode template) and is suppose to also load the bottom menu.
how can I load this NIB file with the UITabBarController included?
my answer to your other question might help. But now I'm a little confused about what you're attempting to do. Let me know and I can help you further.
The modal view will not include the TabBar because a TabBar owns the view controllers represented by each tab. Why do you want the TabBar included in the login view? If you really want a TabBar in your modal view, then you'll need to put your 'log in' view controller inside a TabBar view controller, and then present the TabBar view controller modally.
However, I'd recommend that you have the TabBar in the main part of your app, and present the 'log in' view modally without a TabBar included. Once the user is finished logging in, you can dismiss the 'log in' view, which returns the user to the main part of your app.
To dismiss the modal view controller, set up a delegate system (look through the utility app template to see how this works). If setting up your own delegate protocol is too difficult at the moment, then you can use a workaround in the mean time. In your 'log in' view controller code, after the user has logged in successfully, you can send a message to your parent view controller (the one that presented the modal view) to dismiss it's modal view (your 'log in' view).
[self.parentViewController dismissModalViewControllerAnimated:YES];
This is bad form though. Once you're up to it you should use a delegate callback to have the parent view controller dismiss the modal view.