IT tutorials
 
Mobile
 

iPhone Developer : Working with View Controllers - Presenting a Custom Modal Information View

12/18/2012 5:56:20 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Modal view controllers slide onscreen without being part of your standard view controller stack. Modal views are useful for picking data or presenting information, tasks that might not match well to your normal hierarchy. Any view controller or navigation controller can present a modal controller:

[self presentModalViewController:[[[InfoViewController alloc] init]
    autorelease] animated:YES];

The controller that is presented can be either a view controller or navigation controller. Either way, it helps to provide a Done button to allow the user to dismiss the controller.Figure 1 shows a modal presentation built around a UIViewController instance. The navigation bar at the top of the view was added via a UINavigationBar instance, making this view especially easy to construct in Interface Builder.

Figure 1. This modal view is built using UIViewController with a UINavigationBar.


Normally, a navigation controller-based view requires two .xib files and extra work. Using the bar directly avoided the hassle and provided an elegant solution that mimics the normal look of a UINavigationController presentation.

Recipe 1 shows the two key pieces for this presentation. The presentation is done in the main view controller, with the presentation style set by a segmented control. The InfoViewController, that is, the class that was presented, handles dismissal. Its Done button was connected via IB to the doneReading method. This method asks the view controller’s parent to dismiss the modally presented view controller.

Recipe 1. Presenting and Dismissing a Modal Controller
// Presenting the controller
- (void) info
{
    int segment = [(UISegmentedControl *)self.navigationItem.titleView
        selectedSegmentIndex];
    int styles[3] = {UIModalTransitionStyleCoverVertical,
        UIModalTransitionStyleCrossDissolve,
        UIModalTransitionStyleFlipHorizontal};
    InfoViewController *ivc = [[[InfoViewController alloc] init]
        autorelease];
    ivc.modalTransitionStyle = styles[segment];
    [self presentModalViewController:ivc animated:YES];
}

And...

// Dismissing the controller
- (IBAction) doneReading
{
    [[self parentViewController]
        dismissModalViewControllerAnimated:YES];
}
 
Others
 
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 3) - Using Touch
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 2) - Debugging in the Emulator, Debugging with a Device
- Windows Phone 8 : Writing Your First Phone Application - Adding Code (part 1) - Working with Events
- Windows Phone 8 : Designing with Blend
- Iphone Application : Implementing Location Services - Creating a Location-Aware Application (part 2) - Implementing the Location Manager Delegate
- Iphone Application : Implementing Location Services - Creating a Location-Aware Application (part 1)
- Iphone Application : Implementing Location Services - Understanding Core Location
- Windows Phone 8 : Creating a New Project (part 2) - XAML
- Windows Phone 8 : Creating a New Project (part 1) - Visual Studio
- Developing BlackBerry Tablet Applications : Permissions and Configuration Settings
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us