Navigate to another window from a popup in iPhone - iphone

I used this SampleCode and created two pop-ups, say pop-up1 and pop-up2. From Pop-up1 if a button is pressed another pop-up2 will be displayed. From po-pup2 I need to go for another view. Till pop-up2 its fine, from pop-up2 I couldn't go for a separate view?
I used the below code to remove the popupview.
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
imageShareSubViewController = nil;
I used used the below code to navigate to another view.
#autoreleasepool {
ViewController *obj = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil]autorelease];
[self.navigationController pushViewController:obj animated:TRUE];
obj = nil;
}
But the above is not working fine ( i.e., i could navigate to another view ). How to solve this? Am I wrong anywhere?

create your navigationController, setRootViewController just like this:
//A view controller:
HomeScreen * homeScreen = [[HomeScreen alloc]initWithNibName:#"HomeScreen" bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc]initWithRootViewController:homeScreen];
AppDelegate * delegate = (AppDelegate*)[[UIApplication sharedAplication]delegate];
delegate.window.rootviewcontroller = navigation;
[homeScreen release];
//add other views
HomeScreen * homeScreen2 = [[HomeScreen alloc]initWithNibName:#"HomeScreen" bundle:nil];
[navigation pushViewController: homeScreen2];
[homeScreen2 release];

Related

issue in DDMenuController menuViewController like facebook

My First Question
DDMenuController(facebook split menu) Must be on RootviewController? it can not be on other viewController which we push on rootViewCotroller?
if answer is no then
Second Question
i am trying to make split viewController like facebook for that i am using this sample
https://github.com/devindoty/DDMenuController
now what i want to do is i dont want set DDMenuControl as rootviewcontroller in appdelegate in my rootcontrollers there are view buttons which push my all other ViewController
so what i want is from my rootViewController' Buttons i push another controller and then that view should get pushed and same time there should be DDMenuController too
so what will happen is on navigation bar there wont be back button there will be splitting screen button like facebook and from there i can go to another view controller
now let me tell you what i have achieved so far my rootViewController is getting displayed and then from there i push my other ViewController and on navigation bar splitting button is also getting displayed but its not working let me should you code to make this all clear
this is how i set my rootViewContoller in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
FirstPadViewController *mainController = [[FirstPadViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window.rootViewController = navController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
so it get displayed with some buttons from where i can push my other viewController
this is how i push my other ViewController
- (IBAction)goToCamera:(id)sender {
AROverlayPadViewController *svController = [[AROverlayPadViewController alloc] init];
[self.navigationController pushViewController:svController animated:YES];
[svController release];
svController = nil;
}
so AROverlayPadViewController is getting pushed
and in AROverlayPadViewController's viewWillAppear this is what i do for achieving splitting screen like facebook
-(void)viewWillAppear:(BOOL)animated{
DDMenuController *rootController = [[DDMenuController alloc] initWithRootViewController:self];
LeftController *leftController = [[LeftController alloc] init];
rootController.leftViewController = leftController;
}
splitting button is getting displayed but when i press it is not working
now i really dont have any clue what to do any help will be highly appreciated
Answering the first question: actually it's a yes. This is how you do it, in the method that sends you to your nextScreen:
-(void) goToAnotherController {
OtherViewController *nextScreen = [OtherViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nextScreen];
DDMenuController *menuController = (DDMenuController*)((AppDelegate*) [[UIApplication sharedApplication] delegate]).menuController;
[menuController setRootController:navController animated:YES];
}

Right design pattern for tabbed navigation views?

I've been stuck trying to puzzle this out for a couple days now, and I'll admit I need help.
The root view controller of my application is a tab bar controller. I want to have each tab bar a different navigation controller. These navigation controllers have completely different behavior.
So how do I set this up in terms of classes? Per Apple's documentation, I'm not supposed to subclass UINavigationViewController. So where do I put the code that drives each of these navigation controllers? Does it all get thrown in App Delegate? That would create an impossible mess.
This app should run on iOS 4.0 or later. (Realistically, I can probably require iOS 4.2.)
This is taken from one of my applications. As you say, you are not supposed to subclass UINavigationController, instead you use them as they are and you add viewcontroller on the UINavigationController's. Then after setting the root viewcontroller in each UINavigationController, you add the UINavigationController to the UITabBarController (phew!).
So each tab will "point" to a UINavigationController which has a regular viewcontroller as root viewcontroller, and it is the root viewcontroller (the one you add) that will be shown when a tab is pressed with a (optional) navigationbar at top.
UITabBarController *tvc = [[UITabBarController alloc] init];
self.tabBarController = tvc;
[tvc release];
// Instantiates three view-controllers which will be attached to the tabbar.
// Each view-controller is attached as rootviewcontroller in a navigationcontroller.
MainScreenViewController *vc1 = [[MainScreenViewController alloc] init];
PracticalMainViewController *vc2 = [[PracticalMainViewController alloc] init];
ExerciseViewController *vc3 = [[ExerciseViewController alloc] init];
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *nvc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
[vc1 release];
[vc2 release];
[vc3 release];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
nvc3.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nvc3, nil];
[nvc1 release];
[nvc2 release];
[nvc3 release];
self.tabBarController.viewControllers = controllers;
[controllers release];
This is how I go from one viewcontroller to another one (this is done by tapping a cell in a tableview but as you see the pushViewController method can be used wherever you want).
(this is taken from another part of the app)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.detailedAnswerViewController == nil) {
TestAnsweredViewController *vc = [[TestAnsweredViewController alloc] init];
self.detailedAnswerViewController = vc;
[vc release];
}
[self.navigationController pushViewController:self.detailedAnswerViewController animated:YES];
}
The self.navigationcontroller property is of course set on each viewcontroller which are pushed on the UINavigationController hierachy.

How to handle the view controllers?

Hi guys I am working on an application.Where there is a home screen with 5 buttons.On the click of every button i want to open the screen with tabbar with 5 view controllers.I mean when you click on the button the tabbar is opened.And there are back button on the tab bar view as well .On clicking the back button i want to pop back to the home screen and vice versa.
How to do that guys.Any tutorial ,links,sample code would be appreciated.
Thanks a lot to all
Tabbar controller in a navigation stack is complicated. Since each tab controller can have also navigation controller itself.
Have a WindowManager class. It should own both
- FirstViewController and
- TabbarController
All components and the UITabbarControllers themselves should be instantiated in the WindowManager class.
Its init may have code like this, make similar for two tabbarcontrollers.
self.tabBarController = [[UITabBarController alloc] init];
self.controllers = [[NSMutableArray alloc] init];
// initialize the view controllers and navigation controllers for the tab bar
self.friendsVC = [[FriendsVC alloc] initWithNibName:#"FriendsView" bundle:nil];
UINavigationController *friendsNVC = [[UINavigationController alloc] initWithRootViewController: friendsVC];
friendsNVC.navigationBar.barStyle = UIBarStyleBlack;
[controllers addObject:friendsNVC];
[friendsNVC release];
self.paymentsVC = [[PaymentsVC alloc] initWithNibName:#"PaymentsView" bundle:nil];
UINavigationController *paymentsNVC = [[UINavigationController alloc] initWithRootViewController: paymentsVC];
paymentsNVC.navigationBar.barStyle = UIBarStyleBlack;
[controllers addObject:paymentsNVC];
[paymentsNVC release];
tabBarController.viewControllers = controllers;
tabBarController.selectedIndex = 0;
tabBarController.delegate = self;
self.view = tabBarController.view;
In the WindowManager, you can have two methods like,
[WindowManager showViewController] and
[WindowManager showTabbarController].
- showViewController {
//Initiate View controller and use [self.window addSubView:vc.view];
}
- showTabbarController {
// initiate the tabbar manager
}
You can have a "back" button on top of your first tabbar controller left side, to call the
[WindowManager showViewController];

Is it possible to create a UINavigationController within a ModalPopup?

Hi I have a modalViewController that I am popping up using
[self presentModalViewController:myController animated:YES];
I have an event occurring within myController which I would like to result in another controller being pushed onto the navigation stack ON TOP OF myController (which again has been presented modally). How can I do this?
I have tried the following from within myController:
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:self];
NewController* n = [[NewController alloc] init];
[navController pushViewController:n animated:YES];
[n release];
This does not work however....
First create your second modalViewController
NewController* new = [[NewController alloc] init];
then create navigaitonController like this
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController: new];
navigationController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
then present your navigationController as modalview controller
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
Here you go. Hope it helps.
If i understand right you want to display new navigation stack on top of modal view.
If it is right I think it won't be possible. Modal view is a top one. Even if you'll push new ViewController to the "parent" navigation stack - it won't be available until you'll quite from your modal view.

iphone presentModalViewController

I have an app, inside that an UIViewController is attached on the UIWindow.
on the view of UIViewController, i have added a button and a uiview_1 of size 100x80.
this uiview_1 contains another uiview_2 as subview of same size and this uiview_2 contains a UIImageView or a UIlable at runtime (both UIImageView and UIlable are userinteraction enabled)
now on the touch/click of UIImageView, i want to show a new view using presentModalViewController, the problem is the view is shown and using back button on the navigation bar i come to the previous/main screen.
here the problem come in picture, now i am unable to touch the button or the UIImageView.
both are not responding, but app is not crashed and nor frozen.
what is wrong in that?
Plz help in this...
----- EDIT:
Approach First:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
UIWindow *win = [[UIApplication sharedApplication] keyWindow];
[win addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the Main screen ctrls are not responding to touch – sandy 3 hours ago
Second approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
UIViewController *pushController = [[UIViewController alloc] init];
[self addSubview:pushController.view];
[pushController presentModalViewController:viewNavController animated:YES];
In the swvController i have back button that calls the dismissModelViewController on click >> result is the swvController's back button on navbar is not responding – sandy 3 hours ago
3rd approach:
SWVController *swvController = [[SWVController alloc] init];
UINavigationController *viewNavController = [[UINavigationController alloc] initWithRootViewController:swvController];
SampleAppAppDelegate *appdel = [[UIApplication sharedApplication] delegate]; [appdel.viewController presentModalViewController:viewNavController animated:YES];
>> result is working fine, but the problem is i dont want to use SampleAppAppDelegate,i want to give my small Uiview (100x80) as a ctrl to other person , where my ctrl will not able to get the AppDelegate of thet app at run time. – sandy 3 hours ago
Call this method when you want to present the modal view controller:
- (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
Add this method to your self:
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
Use a toolbar or other button and connect it to this method in your modal view controller:
- (IBAction)done {
[self.delegate flipsideViewControllerDidFinish:self];
}
All code comes from Apple.
How did you handled click/touch on UIImageView? TouchesBegan/Ended?
Try putting some logs (NSLog) and run your app in debug mode (put some breakpoints) to see if control reaches your action method...
Also, when you do presentModalViewController, you do not need to POP out with back button on navigation bar... you only need to dismissModelViewController to hide it.