archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • An Overview of the iPad iOS 5 Application Development Architecture - Techotopia
    and Controller components are objects It is also worth pointing out that applications are not restricted to a single model view and controller In fact an app can consist of multiple view objects controller objects and model objects The way that a view controller object interacts with a Model is through the methods and properties exposed by that model object This in fact is no different from the way one object interacts with another in any object oriented programming environment In terms of the view controller s interactions with the view however things get a little more complicated In practice this is achieved using the Target Action pattern together with Outlets and Actions The Target Action pattern IBOutlets and IBActions When you create an iOS 5 iPad app you will typically design the user interface the view using the Interface Builder tool and write the view controller and model code in Objective C using the Xcode code editor The previous section looked briefly at how the view controller interacts with the model In this section we will look at how the view created in Interface Builder and our view controller code interact with each other When a user interacts with objects in the view for example touching and releasing a button control an event is triggered in this case the event is called a Touch Up Inside event The purpose of the Target Action pattern is to allow you to specify what happens when such events are triggered In other words this is how you connect the objects in the user interface you have designed in the Interface Builder tool to the back end Objective C code you have written in the Xcode environment Specifically this allows you to define which method of which controller object gets called when a user interacts in a certain way with a view object The process of wiring up a view object to call a specific method on a view controller object is achieved using something called an Action An action is a method defined within a view controller object that is designed to be called when an event is triggered in a view object This allows us to connect a view object created within a nib file using Interface Builder to the code that we have written in the view controller class This is one of the ways that we bridge the separation between the View and the Controller in our MVC design pattern As we will see in Creating an Interactive iOS 5 iPad App action methods are declared using the IBAction keyword The opposite of an Action is the Outlet As previously described an Action allows a view object to call a method on a controller object An Outlet on the other hand allows a view controller object method to directly access the properties of a view object A view controller might for example need to set the text on a UILabel object In order to do so an Outlet must

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_the_iPad_iOS_5_Application_Development_Architecture (2016-02-13)
    Open archived version from archive


  • Creating an Interactive iOS 5 iPad App - Techotopia
    h interface UnitConverterViewController UIViewController end As we can see from the above code a new class called UnitConverterViewController has been created that is a subclass of the UIViewController class belonging to the UIKit framework The next step is to extend the subclass to include the two outlets and our action method We will begin by adding outlets for our text field and label objects by declaring appropriate properties in conjunction with the IBOutlet keyword import UIKit UIKit h interface UnitConverterViewController UIViewController property strong nonatomic IBOutlet UILabel resultLabel property strong nonatomic IBOutlet UITextField tempText end Next we need to declare the action that will be called when the user touches the Convert button in our user interface This is declared using the IBAction keyword import UIKit UIKit h interface UnitConverterViewController UIViewController property strong nonatomic IBOutlet UILabel resultLabel property strong nonatomic IBOutlet UITextField tempText IBAction convertTemp id sender end We have now declared that our View Controller class contains a method called convertTemp Having made that declaration we need to implement the method in the implementation source file To do so select the UnitConverterViewController m file so that the contents appear in the editing pane import UnitConverterViewController h interface UnitConverterViewController end implementation UnitConverterViewController void viewDidLoad super viewDidLoad Do any additional setup after loading the view typically from a nib void viewDidUnload super viewDidUnload Release any retained subviews of the main view BOOL shouldAutorotateToInterfaceOrientation UIInterfaceOrientation interfaceOrientation return interfaceOrientation UIInterfaceOrientationPortraitUpsideDown end The first step is to instruct Objective C to synthesize accessor methods for our tempText and resultLabel objects and then to implement the convertTemp method The relevant section of the UnitConverterViewController m file should now read as follows import UnitConverterViewController h implementation UnitConverterViewController synthesize resultLabel tempText void convertTemp id sender double farenheit tempText text doubleValue double celsius farenheit 32 1 8 NSString resultString NSString alloc initWithFormat Celsius f celsius self resultLabel text resultString Before we proceed it is probably a good idea to pause and explain what is happening in the above code Those already familiar with Objective C however may skip the next few paragraphs In this file we are implementing the convertTemp method originally declared in the h file This method takes as a single argument a reference to the sender The sender is the object that triggered the call to the method in this case our Button object Whilst we won t be using this object in the current example this can be used to create a general purpose method in which the behavior of the method changes depending on how i e via which object it was called We could for example create two buttons labeled Convert to Fahrenheit and Convert to Celsius respectively each of which calls the same convertTemp method The method would then access the sender object to identify which button triggered the event and perform the corresponding type of unit conversion Next the code declares a variable of type double in order to handle the fact that the user may have entered a floating point

    Original URL path: http://www.techotopia.com/index.php/Creating_an_Interactive_iOS_5_iPad_App (2016-02-13)
    Open archived version from archive

  • Writing iOS 5 Code to Hide the iPad Keyboard - Techotopia
    outlet by holding down the Ctrl key while clicking and dragging with the mouse from the File s Owner icon to the text field object in the View From the resulting menu select the textField outlet Hiding the Keyboard when the User Touches the Return Key The next step is to wire up our application so that the keyboard is dismissed when the user touches the keyboard Return key To do so we need to write a method that will resign the first responder on the text field in other words hide the keyboard when the return key is pressed Begin by editing the hideKeyboardViewController h interface file to declare the method which we will name textFieldReturn import UIKit UIKit h interface hideKeyboardViewController UIViewController property strong nonatomic IBOutlet UITextField textField IBAction textFieldReturn id sender end Having declared the method we now need to implement it in the hideKeyboardViewController m implementation file import hideKeyboardViewController h implementation hideKeyboardViewController synthesize textField interface hideKeyboardViewController end IBAction textFieldReturn id sender sender resignFirstResponder end In the above method we are making a call to the resignFirstResponder method of the object that triggered the event The first responder is the object with which the user is currently interacting in this instance the virtual keyboard displayed on the iPad screen Having written the code for our method we now need to wire up our user interface so that it gets called at the appropriate time We will perform this task in Interface Builder so select hideKeyboardViewController xib once more Select the text field in the view and display the Connections Inspector View Utilities Connections Inspector in the right hand panel Click on the circle to the right of the Did End on Exit event drag the line to the File s Owner icon and select textFieldReturn from the list of available methods Click on the Run button in the Xcode toolbar When the application appears in the iOS Simulator select the text field so that the keyboard appears and then touch the Return key The keyboard should subsequently disappear from view Hiding the Keyboard when the User Taps the Background The second mechanism for hiding the keyboard involves wiring up an event to be called when the user touches the background view of the screen We will begin the process by writing the action method to perform this task From within Xcode select the hideKeyboardViewController h file and add a declaration for our new backgroundTouched action method import UIKit UIKit h interface hideKeyboardViewController UIViewController property nonatomic strong IBOutlet UITextField textField IBAction textFieldReturn id sender IBAction backgroundTouched id sender end Select the hideKeyboardViewController m file and implement the action by calling the resignFirst Responder method of our textField object import hideKeyboardViewController h interface hideKeyboardViewController end implementation hideKeyboardViewController synthesize textField IBAction textFieldReturn id sender sender resignFirstResponder IBAction backgroundTouched id sender textField resignFirstResponder end Having written the code for our action method we now need to make sure it gets called when the user touches the background view This involves some

    Original URL path: http://www.techotopia.com/index.php/Writing_iOS_5_Code_to_Hide_the_iPad_Keyboard (2016-02-13)
    Open archived version from archive

  • Establishing Outlets and Actions using the Xcode Assistant Editor - Techotopia
    source file that is to be displayed In order to change to another file relating to the same class simply click on the file name in the jump bar located across the top of the Assistant editor panel and select the required file from the resulting menu To switch between automatic and manual file selection click on the Automatic entry in the jump bar and select the Manual menu option The Manual sub menus may then be used to navigate to the required file including selections from outside of the current class Using the Assistant Editor In the remainder of this chapter we will create a simple project and use it to demonstrate the ease with which outlets and actions may be declared using the Assistant Editor For the purposes of this example create a new Xcode iPad project named Assistant using the Single View Application template Once the project has been created select the AssistantViewController xib file so that the Interface Builder panel appears and then drag and drop a button and label onto the view canvas Figure 14 3 The ultimate goal of the application is to display a message on the label when the button is touched In order to achieve this it will be necessary to implement an action method for the button to call and an outlet to provide access to the text property of the label As outlined in the chapter entitled Creating an Interactive iOS 5 iPad App this can be achieved by manually adding the appropriate declarations to the interface and implementation files of the view controller This time however the Assistant Editor is going to do the work for us Adding an Outlet using the Assistant Editor Assuming that the Interface Builder panel is still visible display the Assistant Editor panel as outlined earlier in the chapter and make sure that the assistant has selected the AssistantViewController h file In order to establish an outlet for the label object simply Ctrl click on the label object in the view and drag the resulting line to the area immediately beneath the interface directive in the Assistant Editor panel as illustrated in Figure 14 4 Figure 14 4 Upon releasing the line the configuration panel illustrated in Figure 14 5 will appear requesting details about the outlet to be defined Figure 14 5 Since this is an outlet the Connection menu should be left as Outlet The type and storage values are also correct for this type of outlet The only task that remains is to enter a name for the outlet so in the Name field enter statusLabel before clicking on the Connect button Once the connection has been established select the AssistantViewController h file from the project navigator panel and note that the outlet property has been declared for us by the assistant import UIKit UIKit h interface AssistantViewController UIViewController property strong nonatomic IBOutlet UILabel statusLabel end An inspection of the AssistantViewController m file should reveal that the assistant has also

    Original URL path: http://www.techotopia.com/index.php/Establishing_Outlets_and_Actions_using_the_Xcode_Assistant_Editor (2016-02-13)
    Open archived version from archive

  • Understanding iPad iOS 5 Views, Windows and the View Hierarchy - Techotopia
    the implications of enabling rotation in an application without taking the additional steps to reformat the view to match the change in orientation Having rotated the device only the top button is visible and it is still centered assuming that the device is in portrait mode The second button is similarly positioned resulting in it being outside the viewable area of the screen In order to ensure the correct layout of the user interface it is necessary to make some changes to the autosize settings of the two buttons The current settings for a view are accessed from within Interface Builder by selecting the component and displaying the Size Inspector View Utilities Size Inspector The following figure shows the Size Inspector for the top button in our user interface The section of this window that is of interest to us is the area labeled Autosizing and in particular the white box on the left The outer box represents the superview and the inner box represents the subview that is contained within the superview Any autosizing settings that are configured on a subview are relative to the superview Within the subview box are two intersecting lines with arrows at each end These vertical and horizontal lines indicate whether the height and width of the selected view object should increase or decrease in proportion to size changes in the corresponding superview A faint dotted line indicates that the currently selected view object is not to resize in relation to the superview A solid red line on the other hand indicates that it should resize proportionally to the parent view The graphic to the right of the white box provides a visual representation of how the view will behave based on the current settings The red box represents the subview and the white box represents the containing superview Click on the horizontal line to change it to solid red and see how the width of the red box representing the button grows and shrinks as the containing superview size changes Similarly enable resizing for the height of the button and observe how the height of the button also now changes proportionally to the superview These two settings correspond to the UIViewAutoResizingFlexibleHeight and UIViewAutoResizingFlexibleWidth autoresizing mask properties The lines separating the four sides of the inner subview and the outer superview boxes are referred to as struts and control what happens to the margin between each side of the subview and the corresponding sides of the superview when the latter resizes as the result of an orientation change When a strut is enabled indicated by the solid red lines the corresponding margin remains fixed when the superview resizes In the above example the top and left hand margins are fixed which explains why the position of the top left hand corner of the button does not move in the graphical representation when the superview resizes When the strut is turned off symbolized by the faint dotted lines the margin changes proportionally to the change

    Original URL path: http://www.techotopia.com/index.php/Understanding_iPad_iOS_5_Views,_Windows_and_the_View_Hierarchy (2016-02-13)
    Open archived version from archive

  • Using Xcode Storyboarding with iOS 5 - Techotopia
    Having implemented the scenes the next step is to configure segues between the scenes Figure 17 4 Configuring Storyboard Segues As previously discussed a segue is the transition from one scene to another within a storyboard Within the example application touching the Go to Scene 2 button will segue to scene 2 Conversely the button on scene 2 is intended to return the user to scene 1 To establish a segue hold down the Ctrl key on the keyboard click over a control in this case the button on scene 1 and drag the resulting line to the scene 2 view Upon releasing the mouse button a menu will appear Select the Modal menu option to establish the segue Repeat these steps to establish a segue between the button on scene 2 and the scene 1 view As segues are established Interface Builder displays lines indicating the connections Figure 17 5 As more scenes are added to a storyboard it becomes increasingly difficult to see more than a few scenes at one time on the canvas To zoom out simply double click on the canvas To zoom back in again simply double click once again on the canvas Alternatively use the zoom panel located in the bottom right hand corner of the storyboard canvas Configuring Storyboard Transitions Xcode provides the option to change the visual appearance of the transition that takes place during a segue By default a Cover Vertical transition is performed whereby the new scene slides vertically upwards from the bottom of the view to cover the currently displayed scene To change the transition select the corresponding segue line display the attributes inspector View Utilities Show Attributes Inspector and modify the Transition setting In Figure 17 6 the transition has been changed to Cross Dissolve Figure 17 6 To delete a segue from a storyboard simply select the arrow and press the keyboard delete key Associating a View Controller with a Scene At this point in the example we have two scenes but only one view controller the one created by Xcode when we selected Single View Application Clearly in order to be able to add any functionality behind scene 2 it too will need a view controller The first step therefore is to add the files for a view controller to the project Ctrl click on the storyboard target at the top of the project navigator panel and select New File from the resulting menu In the new file panel select Objective C class and click Next to proceed On the options screen verify that the Subclass of menu is set to UIViewController that the Targeted for iPad option is selected and that With XIB for user interface is deselected since the view already exists in the storyboard there is no need for a user interface NIB file and name the class Scene2ViewController Select the MainStoryboard storyboard file in the project navigator panel and second scene in the canvas area followed by the View Controller item in

    Original URL path: http://www.techotopia.com/index.php/Using_Xcode_Storyboarding_with_iOS_5 (2016-02-13)
    Open archived version from archive

  • Using Xcode Storyboards to create an iOS 5 iPad Tab Bar Application - Techotopia
    file named MainStoryboard storyboard file has also been created Renaming the Initial View Controller The next step in creating the application involves renaming the TabBarViewController class provided by Xcode to a more descriptive name Since this view controller presents the view that will be displayed when the user touches the first tab on the tab bar we will name this class Tab1ViewController To achieve this select the TabBarViewController h file and use the mouse to highlight the TabBarViewController class name in the editing panel With the name highlighted select the Edit Refactor Rename menu option In the resulting panel enter Tab1ViewController into the text box and click on Preview In the preview panel select the Save button followed by the option to Disable snapshots Adding the View Controller for the Second Content View The ultimate goal of this chapter is to create a tab bar based application consisting of two tabs with corresponding views Xcode has already created the first view controller for us and we have subsequently renamed this class The next step therefore is to add the view controller for the second view To achieve this select the File New File menu option and on the resulting panel select Objective C class Click Next and on the next screen name the new class Tab2ViewController and change the Subclass of menu to UIViewController Verify that the Targeted for iPad option is selected before clicking Next to proceed with the creation process Adding the Tab Bar Controller to the Storyboard As previously explained the navigation between view controllers in a Tab Bar based interface is handled by a Tab Bar Controller It will be necessary therefore to add one of these to our storyboard Begin by selecting the MainStoryBoard storyboard file in the Xcode project navigator panel and note as illustrated in Figure 18 1 that the storyboard currently only contains the original view controller instance added for us by Xcode when the project was created Figure 18 1 In order to add a Tab Bar Controller to the storyboard select the Tab1 View Controller in the storyboard design area and select the Editor Embed In Tab Bar Controller menu option The Tab Bar Controller will subsequently appear in the storyboard already connected to the Tab Bar Controller as shown in Figure 18 2 Figure 18 2 Now that the Tab Bar Controller has been added the next task is to add a view controller to the storyboard that will correspond to the Tab2ViewController class previously added to the project Adding a Second View Controller to the Storyboard The second view controller may be added to the storyboard simply by dragging and dropping one from the Object Library panel View Utilities Show Object Library Once the new view controller has been added to the storyboard canvas select it so that it is highlighted with a blue border and then display the Identity Inspector panel View Utilities Show Identity Inspector Within the inspector panel change the Class setting from UIViewController to

    Original URL path: http://www.techotopia.com/index.php/Using_Xcode_Storyboards_to_create_an_iOS_5_iPad_Tab_Bar_Application (2016-02-13)
    Open archived version from archive

  • An Overview of iPad iOS 5 Table Views and Xcode Storyboards - Techotopia
    that you have an understanding of table views in order to be able to effectively use split views Historically table views have been one of the more complex areas of iOS user interface implementation In recognition of this fact Apple has introduced entirely new ways to implement table views through the use of the Xcode Storyboard feature The goal of this chapter is to provide an overview of the concept of the UITableView class together with an introduction to the ways in which storyboards can be used to ease the table view implementation process Once these basics have been covered a series of chapters starting with Using Xcode Storyboards to Build Dynamic TableViews with Prototype Table View Cells will work through the creation of example projects intended to demonstrate the use of storyboards in the context of table views An Overview of the Table View Table Views present the user with data in a list format and are represented by the UITableView class of the UIKit framework The data is presented in rows whereby the content of each row is implemented in the form of a UITableViewCell object By default each table cell can display a text label textLabel a subtitle detailedTextLabel and an image imageView More complex cells can be created by either adding subviews to the cell or subclassing UITableViewCell and adding your own custom functionality and appearance Static vs Dynamic Table Views When implementing table views using an Xcode storyboard it is important to understand the distinction between static and dynamic tables Static tables are useful in situations when a fixed number of rows need to be displayed in a table The settings page for an application for example would typically have a predetermined number of configuration options and would be an ideal candidate for a static table Dynamic tables also known as prototype based tables on the other hand are intended for use when a variable number of rows need to be displayed from a data source Within the storyboard editor Xcode allows you to visually design a prototype table cell which will then be replicated in the dynamic table view at runtime in order to display data to the user The Table View Delegate and dataSource Each table view in an application needs to have a delegate and a dataSource associated with it with the exception of static tables which do not have data source The dataSource implements the UITableViewDataSource protocol which basically consists of a number of methods that define title information how many rows of data are to be displayed how the data is divided into different sections and most importantly supplies the table view with the cell objects to be displayed The delegate implements the UITableViewDelegate protocol and provides additional control over the appearance and functionality of the table view including detecting when a user touches a specific row defining custom row heights and indentations and also implementation of row deletion and editing functions Table View Styles Table views may be configured

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_iPad_iOS_5_Table_Views_and_Xcode_Storyboards (2016-02-13)
    Open archived version from archive



  •