2

IPhone application - adding another view

 3 years ago
source link: https://www.codesd.com/item/iphone-application-adding-another-view.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

IPhone application - adding another view

advertisements

I am working on an iPhone app but found that I require another view / window to get the user to input and save data / information there.

How do I add another view? Do I add it in interface builder and then link it in the main app delegate or will it have its own .h and .m files.

I selected a window view app to start with, do I need to start over with a flip side view app or can this just be added in anyway if I have the correct code there.

manny thanks


The Window app is perfect for you. In your AppDelegate file, you should have a section like this:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    //instantiate the venue view controller object
    YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourView" bundle:[NSBundle mainBundle]];

    // Configure and show the window
    [window addSubview:[yourViewController view]];
    [window makeKeyAndVisible];

}

This is the part of the code that declares, allocates and adds your custom view to the window. You have a couple choices for how to add the second view. You can either add it in place of this one, or add it after this one using a Navigation Controller. To add the navigation controller, change the above method to look like this:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

//instantiate the venue view controller object
YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourView" bundle:[NSBundle mainBundle]];
    UINavigationController *yourViewControllerWrapper = [[UINavigationController alloc] initWithRootViewController: yourViewController];

// Configure and show the window
[window addSubview:[yourViewControllerWrapper view]];
[window makeKeyAndVisible];

}

There, we create your custom view, then wrap it in a navigation controller. The navigation controller is what gets added to the window. Next the code to switch to the second view would look like this, assuming you switch views on a button press:

-(IBAction)switchViewController{
    MySecondViewController *secondViewController = [[MySecondViewController alloc] init];

    [self.navigationController pushViewController:secondViewController];
}

Of course, you should replace the line

MySecondViewController *secondViewController = [[MySecondViewController alloc] init];

with the proper way of instantiating your second view controller. This could be from a nib file like above, or programmatically.

As far as creating the view files, you should create a nib in Interface builder for the layout of everything, then create a .h and .m file for the ViewController code itself.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK