IT tutorials
 
Mobile
 

iPhone Application Development : Implementing File System Storage (part 2) - Adding a Create Card View Controller

9/30/2011 11:25:21 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Adding a Create Card View Controller

We now have the complete view for using the flash cards, but users also need to be able to create new cards. When users press the Add button in the top toolbar, we’ll show them another view to capture the question and answer for the new flash card. This new view will have its own controller and NIB.

Select the Classes group and then select File, New File; then the UIViewController subclass template. Make sure the Targeted for iPhone and With XIB for User Interface check boxes are selected, and click the Next button. Name the controller CreateCardViewController, make sure the Also Create CreateCardViewController.h check box is selected, and click the Finish button. Drag the new CreateCardController.xib file from the Classes group to the Resources group to keep the project tidy.

Preparing the Second View Controller

The new view controller needs outlets to access the two text fields that’ll be on the view that will contain the question and answer the user typed. It also needs a delegate to call back to the FlashCardsViewController object when the user wants to save a new card or just dismiss the view. There will be an action for each of the user’s two options: save and cancel.

Click the CreateCardViewController.h file in the Classes group. Add a CreateCardDelegate protocol with two methods: didCancelCardCreation and didCreateCardWithQuestion:answer. Both arguments to the second method are NSString objects. Add the save and cancel actions and add an outlet and property for the question and answer text fields and a property for the CreateCardDelegate. After you’ve added the delegate, outlets, actions, and properties, your CreateCardViewController.h file should look like Listing 4.

Listing 4.
#import <UIKit/UIKit.h>

@protocol CreateCardDelegate <NSObject>

-(void) didCancelCardCreation;
-(void) didCreateCardWithQuestion:(NSString *)question
answer:(NSString *)answer;

@end

@interface CreateCardViewController : UIViewController {

IBOutlet UITextField *question;
IBOutlet UITextField *answer;
id cardDelegate;
}

@property (nonatomic, retain) UITextField *question;
@property (nonatomic, retain) UITextField *answer;
@property (nonatomic, assign) id<CreateCardDelegate> cardDelegate;

-(IBAction) save;
-(IBAction) cancel;

@end

Sorry to bug you about this, but you know what to do. Edit the CreateCardViewController.m file to include the necessary @synthesize lines for the properties:

@synthesize cardDelegate;
@synthesize question;
@synthesize answer;

Modify dealloc to include the objects that were retained:

- (void)dealloc {
[question release];
[answer release];
[super dealloc];
}

Now, the user interface for creating cards.

Creating the User Interface

Open Interface Builder by double-clicking the CreateCardViewController.xib file in the Resources group. Then complete the following steps to lay out the UI and connect the outlets and actions:

1.
Open the Library (Shift+Command+L) and drag a toolbar to the very top of the view.

2.
Click the Item button until just the button is selected, open the Attributes Inspector (Command+1), and choose Save from the Identifier Properties drop-down list.

3.
From the Library, drag one Bar Button item to the top toolbar.

4.
Click the new button until just the button is selected, open the Attributes Inspector (Command+1), and choose Cancel from the Identifier Properties drop-down list.

5.
Within the Library, search for “space.” Drag a Flexible Space Bar Button item to the leftmost position in the top toolbar.

6.
Drag two text fields onto the view below the toolbar.

7.
Position one of the text fields under the top toolbar and against the left-alignment guide. Size the label wider to the right- and left-alignment guides and about one-third of the view. Click the text field, open the Attributes Inspector (Command+1), and change the Text attribute to Question?; change the alignment to centered, change the Border attribute to the leftmost style, and change the Correction Text Input Traits attribute to No.

8.
Position the second text field under the first and against the left-alignment guide. Size the label wider to the left and right-alignment guides and about one-third of the view. Click the text field, open the Attributes Inspector (Command+1), and change the Text attribute to Answer.; change the alignment to centered, change the Border attribute to the leftmost style, and change the Correction Text Input Traits attribute to No. Your UI should now look like Figure 5.

Figure 5. The create card UI.


9.
Connect the two label outlets, question and answer, to the respective labels.

10.
Connect the two actions, cancel and save, to the respective buttons in the view. Save the XIB file, quit Interface Builder, and return to Xcode.
 
Others
 
- iPhone Application Development : Implementing File System Storage (part 1)
- iPhone Application Development : Understanding the iPhone File System Sandbox
- Enterprise Security on the Mobile OS (part 2) - Application Sandboxing, Signing, and Permissions
- Enterprise Security on the Mobile OS (part 1) - Device Security Options & Encryption
- Mobile Geolocation : Geolocation Implementation & Risks of Geolocation Services
- Windows Phone 7 : Spicing Up the User Interface with the Silverlight Toolkit (part 3)
- Windows Phone 7 : Spicing Up the User Interface with the Silverlight Toolkit (part 2)
- Windows Phone 7 : Spicing Up the User Interface with the Silverlight Toolkit (part 1)
- Windows Phone and .NET : Looking Closely at Visual Studio Development for Windows Phone
- Introduction to Android : Android 2.2 (Froyo) & Android 2.3 (Gingerbread)
 
 
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