How to change viewcontroller on buttonTapped with iCarousel? - switch-statement

I have a viewcontroller with an iCarousel.
When I tap on an item that I know how to display an UIalert but, now I want to change view controller to go on an other already created viewcontroller

I'm guessing you need something like this:
MyOtherViewControllersName *vc =[[MyOtherViewControllersName alloc]initWithNibName:#"MyOtherViewControllersName" bundle:nil];
[self presentModalViewController:vc animated:YES];
Just put it in the same method where you're generating the alert message.

Related

iOS how to display new UIView?

New to iOS dev. Kindly correct me if i am wrong?
I have a UIWindow, and rootviewcontroller is :
#interface ViewController : UIViewController
{
IBOutlet UIButton *but;
}
#property (nonatomic, strong) UIButton *but;
-(IBAction) butButtonPressed;
#end
ie: If i make this Viewcontroller as a root view controller, the UIView that is available in the ViewController is displayed. Understood.
I have created a new class inherited from UIViewController, and along with its .xib file.
So xib file name is : view1.xib,
My Objective is to display this view when the button is pressed.
Now i have created a button and button press invokes butButtonPressed. Inside of butButtonPressed, i did the following.
myViewController *vcontroler = [[ViewController alloc] initWithNibName:#"view1" bundle:nil];
[self.view.window addSubview:vcontroler.view];
Application crashes. What am i doing wrong ? Kindly point out.
This...
[self.view.window addSubview:vcontroler.view];
...is a really bad strategy (and I seriously wish I knew where people are finding it as a way of showing views). If you create a view controller, you should use it rather than just treating it as a temporary container that you can rip views out of.
If you want vcontroler to look like a child of your first controller (and you have a UINavigationController), use pushViewController:animated:. Otherwise you can show it as modal with presentModalViewController:animated:.
If you only want to add a view to the existing display, put the view in ViewController's hierarchy and show/hide it.
If you absolutely must have it as a sub-controller of ViewController then you need to keep a reference to it and manage its lifecycle inside the owning controller.

Detect if UIViewController is running inside an existing UINavigationController

I'm creating a generic reusable UIViewController component that people can add to their applications. It requires a navigation bar at the top where it will add some buttons.
I can easily create a navigationBar and add the buttons, but if the developer using my component is adding the view as part of an existing navigation structure, they might end up with 2 navigation bars.
In other words, if my view is loaded with:
[self.navigationController pushViewController:controller animated:YES];
then it should not add a navigationbar and use what's already there. If the view is loaded with:
[self presentModalViewController:controller animated:YES];
then it should add its own navbar.
Without requiring the developer that uses my controller to do something like a useNavBar:YES, is there a way to do this automatically?
Something like a [self isRunningInsideANavigationController] or [self hasNavigationBar] would do.
You could use self.navigationController for that purpose. It will return nil or the navigationController.

Adding UINavigationController to xCode Tab Bar Application Template

How to add UINavigationController to xCode Tab Bar Application Delegate?
My structure is based on xCode Tab Bar Application Delegate, with 2 tabs, First View & Second View respectively. For First View, I added a UITableView. I just want to make use of UINavigationController function [self.navigationController pushViewController:animated:] to push a subview and allow a navigation bar to be shown in subview. After pushing the subview, the tab bar must still be there.
Sounds simple, but I have no idea how to achieve it. Please help.
I started with a Window-based template instead and did this to achieve the same thing.
I created my NavigationControllers and TabBarController in my app delegate manually.
In your:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add this:
//Seeting up the Navigation controllers and pushing our TableView controllers.
UINavigationController *unvc1 = [[UINavigationController alloc] init];
UINavigationController *unvc2 = [[UINavigationController alloc] init];
[unvc1 pushViewController:someViewController1 animated:NO];
[unvc2 pushViewController:someViewController2 animated:NO];
[someViewController1 release];[someViewController2 release];//Releasing our TableView controllers.
//Setting up the TabBar controller and pushing our Navigation controllers.
UITabBarController *tbvc = [[UITabBarController alloc] init];
tbvc.viewControllers = [NSArray arrayWithObjects:unvc1, unvc2, nil];
[unvc1 release];[unvc2 release]; //releasing our Navigation controllers.
I hope this helps.
I did this using presentModalViewController:animated . I added tabBar Controller in the modalView. In the method didSelectRowAtIndexPath use this presentModalViewController:animated .I might not be perfect but I had the same problem, but now my app works as I need.

To Use NavigationViewController or NOT

I am creating an application which displays map using MKMapView control. I have a button on the map that takes me to different view (information view) using the following code:
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
self.view = infoViewController.view;
Now after going to the information view I want to go back again to the main view which displays the map without having to loose anything. Is NagivationControlller my best option to use in this scenario?
Try this,
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
[self.navigationController pushViewController:infoViewController animated:YES];
[infoViewController release];
once you push viewController back button is available to come back to rootViewController.

has Presenting modal view controller in iOS 4.3 for iPad changed?

Has Presenting modal view controller in iOS 4.3 for iPad changed?
I created a new view application, then created a new UIViewControllerSubclass called "One", I then changed the background of One.xib to black, in the applications view controller's viewDidLoad method I placed in the code below. I ran the project in the simulator and receive the log that the "Code has run..."
The project can be downloaded from here....Download Source Code of Project
#import "One.h"
- (void)viewDidLoad
{
One *newItemViewController = [[One alloc] initWithNibName:#"One" bundle:nil];
newItemViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:newItemViewController animated:YES];
[newItemViewController release];
NSLog(#"Code has run...");
}
Try putting your this in the viewDidAppear method instead of viewDidLoad.

Resources