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".
  • Implementing iPad iOS 6 TableView Navigation using Xcode Storyboards - Techotopia
    made possible by the addition of a Navigation Controller to the storyboard This can be added by selecting the Car Table View Controller item in the storyboard so that it highlights in blue and then selecting the Xcode Editor Embed In Navigation Controller menu option Once performed the storyboard will appear as outlined in Figure 27 2 Figure 27 2 Establishing the Storyboard Segue When the user selects a row within the table view a segue needs to be triggered to display the car detail view controller In order to establish this segue Ctrl click on the prototype cell located in the Car Table View Controller scene and drag the resulting line to the Car Detail View Controller scene Upon releasing the line select the push option from the resulting menu The storyboard will update to display a segue connection between the table view cell and the view controller In code that will be implemented later in this chapter it will be necessary to reference this specific segue In order to do so it must therefore be given an identifier Click on the segue connection between Car Table View Controller and Car Detail View Controller display the Attributes Inspector View Utilities Show Attributes Inspector and change the Identifier value to ShowCarDetails In addition a toolbar should have appeared in both scenes Double click on these toolbars and change the title to Cars and Car Details respectively Figure 27 3 Build and run the application and note that selecting a row in the table view now displays the second view controller which in turn has a button in the toolbar to return to the table view Clearly we now need to do some work on the CarDetailViewController class so that details about the selected car are displayed in the view Modifying the CarDetailViewController Class For the purposes of this example application the car detail view is going to display the make and model of the selected car together with a photograph In order to achieve this the class is going to need outlets to two labels and a UIImageView object which will later be added to the view In addition to the outlets the class is also going to need an internal data model that contains information about the car It will be the job of the table view controller to update this model prior to the segue occurring so that it reflects data on the selected car For the sake of simplicity the data model will take the form of an NSArray object Select the CarDetailViewController h file and modify it as follows to declare this array import UIKit UIKit h interface CarDetailViewController UIViewController property strong nonatomic NSArray carDetailModel end The next step is to design the user interface for the detail view and connect the user interface elements to outlets properties Select the storyboard file in the navigation controller ensure that the view is zoomed in and drag and drop items from the object library so that the user

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

  • Using an Xcode Storyboard to Create a Static iPad iOS 6 Table View - Techotopia
    Controller scene so that it is highlighted in blue Display the Identity Inspector panel View Utilities Show Identity Inspector and use the Class drop down menu to change the class from UITableViewController to StaticTableViewController Changing the Table View Content Type By default Xcode makes the assumption that the table view is to be dynamic The most obvious indications of this are the presence of a Prototype Cell within the table view and the words Prototype Content in the view Click within the grey area of the table view and display the Attributes Inspector panel note that the storyboard view must be zoomed in at this point The Content attribute will currently be set to Dynamic Prototypes so use the menu to change the attribute to Static Cells At this point the table view within the storyboard will change to display a static table containing three rows as illustrated in Figure 28 1 Figure 28 1 Designing the Static Table With a static table view added to the project the full power of Interface Builder is available to us to design the layout and content of the table and cells The first step is to change the table view style With the table view selected in the storyboard and the Attributes Panel displayed change the Style attribute to Grouped and the Sections attribute to 2 The table view should now consist of two group sections with three rows per section For the purposes of this example we only need two rows in the top section so click on the third row to highlight it and press the delete key on the keyboard Note that additional rows may be added if required by selecting the corresponding table view section and changing the Rows property In the case of the bottom section only one row is required so click on the bottom two rows and delete them from the view Select the top section by clicking on the shaded area immediately above the cells note that sections may also be selected by clicking on the Table View Section item in the toolbar strip located across the top of the storyboard editor and also from the hierarchy list located in the Document Outline panel of the Xcode window Within the Attributes Inspector change the Header property to Car Details Repeat this step on the lower section to change the header to Car Photo Next stretch the height of the single cell in the bottom section so that it fills the remainder of the table view such that the table view appears as illustrated in the following figure Figure 28 2 Adding Items to the Table Cells Using the Object Library panel drag and drop an Image View object into the cell in the bottom section and resize it to fill most of the available space Also drag and drop labels into the two cells in the top section and set appropriate text properties so that the layout resembles that of Figure 28 3 Figure

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

  • An iPad iOS 6 Split View and Popover Example - Techotopia
    each view In addition a navigation controller is created for each with the corresponding view controller declared as the root view controller The code then assigns our detail view controller object to the detailViewController property of our master view controller object This will be useful when we need to access this object in code later in the chapter An instance of the split view controller class is then created and an array containing the master and detail navigation controllers assigned to the split view object s viewControllers property The detail view controller is declared as the delegate for the split view controller which in turn is assigned as root view controller of the window prior to being displayed Configuring Master View Items The root view controller created for us by Xcode is actually a subclass of UITableView The next step therefore is to configure the table view to display the list of web sites For this purpose we will need to configure two array objects to store the web site names and corresponding URL addresses Select the SplitViewMasterViewController h file and modify it as follows to declare these two arrays import UIKit UIKit h class SplitViewDetailViewController interface SplitViewMasterViewController UITableViewController property nonatomic retain NSArray siteNames property nonatomic retain NSArray siteAddresses property strong nonatomic SplitViewDetailViewController detailViewController end Having declared the arrays modify the SplitViewMasterViewController m file to initialize the arrays in the viewDidLoad method Note that Xcode has already added some code to the viewDidLoad method for the template example so be sure to remove this before adding the new code below void viewDidLoad super viewDidLoad siteNames NSArray alloc initWithObjects Yahoo Google Apple eBookFrenzy nil siteAddresses NSArray alloc initWithObjects http www yahoo com http www google com http www apple com http www ebookfrenzy com nil self tableView selectRowAtIndexPath NSIndexPath indexPathForRow 0 inSection 0 animated NO scrollPosition UITableViewScrollPositionMiddle There are a number of methods that must be implemented in order for the items to appear within the table view object Fortunately Xcode has already placed template methods for us to use in the SplitViewMasterViewController m file First modify the numberOfRowsInSection method to notify the table view of the number of items to be displayed in this case a value equal to the number of items in our siteNames array Since there is only one section in the table also modify the numberOfSectionsInTableView method accordingly Note that Xcode has once again added some code for the template example so be sure to remove this code NSInteger numberOfSectionsInTableView UITableView tableView return 1 NSInteger tableView UITableView tableView numberOfRowsInSection NSInteger section return siteNames count Next modify the cellForRowAtIndexPath method to return the item to be displayed using the row number argument as an index into the siteNames array UITableViewCell tableView UITableView tableView cellForRowAtIndexPath NSIndexPath indexPath static NSString CellIdentifier Cell UITableViewCell cell tableView dequeueReusableCellWithIdentifier CellIdentifier if cell nil cell UITableViewCell alloc initWithStyle UITableViewCellStyleDefault reuseIdentifier CellIdentifier NSDate object objects indexPath row cell textLabel text object description cell textLabel text siteNames indexPath row return cell Before performing a test

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

  • Working with iPad Files on iOS 6 - Techotopia
    removed and an optional NSError object The success of the operation is as usual reported in the form of a boolean YES or NO return value NSFileManager filemgr filemgr NSFileManager defaultManager if filemgr removeItemAtPath tmp myfile txt error NULL YES NSLog Remove successful else NSLog Remove failed Creating a Symbolic Link A symbolic link to a particular file may be created using the createSymbolicLinkAtPath method This takes as arguments the path of the symbolic link the path to the file to which the link is to refer and an optional NSError object For example the following code creates a symbolic link from Users demo file1 txt that links to the pre existing file tmp myfile txt NSFileManager filemgr filemgr NSFileManager defaultManager if filemgr createSymbolicLinkAtPath Users demo file1 txt withDestinationPath tmp myfile txt error NULL YES NSLog Remove successful else NSLog Remove failed Reading and Writing Files with NSFileManager The NSFileManager class includes some basic file reading and writing capabilities These capabilities are somewhat limited when compared to the options provided by the NSFileHandle class but can be useful nonetheless Firstly the contents of a file may be read and stored in an NSData object through the use of the contentsAtPath method NSFileManager filemgr NSData databuffer filemgr NSFileManager defaultManager databuffer filemgr contentsAtPath tmp myfile txt Having stored the contents of a file in an NSData object that data may subsequently be written out to a new file using the createFileAtPath method databuffer filemgr contentsAtPath tmp myfile txt filemgr createFileAtPath tmp newfile txt contents databuffer attributes nil In the above example we have essentially copied the contents from an existing file to a new file This however gives us no control over how much data is to be read or written and does not allow us to append data to the end of an existing file If the file tmp newfile txt in the above example had already existed it and any data it contained would have been overwritten by the contents of the source file Clearly some more flexible mechanism is required This is provided by the Foundation Framework in the form of the NSFileHandle class Working with Files using the NSFileHandle Class The NSFileHandle class provides a range of methods designed to provide a more advanced mechanism for working with files In addition to files this class can also be used for working with devices and network sockets In the following sections we will look at some of the more common uses for this class Creating an NSFileHandle Object An NSFileHandle object can be created when opening a file for reading writing or updating in other words both reading and writing This is achieved using the fileHandleForReadingAtPath fileHandleForWritingAtPath and fileHandleForUpdatingAtPath methods respectively Having opened a file it must subsequently be closed when we have finished working with it using the closeFile method If an attempt to open a file fails for example because an attempt is made to open a non existent file for reading these methods return nil For

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

  • IOS 6 iPad Directory Handling and File I/O – A Worked Example - Techotopia
    panel View Utilities Show Object Library onto the view Double click on the button and change the text to Save Position the components and resize the width of the text field so that the layout appears as illustrated in Figure 36 1 Figure 36 1 Select the Text Field object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the FileExampleViewController h file Ctrl click on the text view object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named textBox Ctrl click on the button object and drag the line to the area immediately beneath the newly created outlet in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Touch Up Inside event configured to call a method named saveText Select the text view object display the Attributes Inspector and delete the sample Latin text Checking the Data File on Application Startup Each time the application is launched by the user it will need to check to see if the data file already exists if the user has not previously saved any text the file will not have been created If the file does exist the contents need to be read by the application and displayed within the text view A good place to put initialization code of this nature is in the viewDidLoad method of the view controller With this in mind select the FileExampleViewController m file scroll down to the viewDidLoad method and edit it as follows void viewDidLoad super viewDidLoad NSFileManager filemgr NSString dataFile NSString docsDir NSArray dirPaths filemgr NSFileManager defaultManager Identify the documents directory dirPaths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask YES docsDir dirPaths 0 Build the path to the data file dataFile docsDir stringByAppendingPathComponent datafile dat Check if the file already exists if filemgr fileExistsAtPath dataFile Read file contents and display in textBox NSData databuffer databuffer filemgr contentsAtPath dataFile NSString datastring NSString alloc initWithData databuffer encoding NSASCIIStringEncoding textBox text datastring Before proceeding we need to take some time to talk about what the above code is doing First we declare some variables that will be used in the method and then create an instance of the NSFileManager class Because each iOS application on an iPad device has its own Documents directory we next make the appropriate calls to identify the path to that directory and assign the result to docsDir Once we know where the documents directory is located we construct the full path to our file which is named datafile dat before checking whether the file already exists If it exists we read the contents of the file and assign it to the text property of our text view object so that it is visible to the user Finally we release the file manager object Now that we have the initialization code implemented we need to write the

    Original URL path: http://www.techotopia.com/index.php/IOS_6_iPad_Directory_Handling_and_File_I/O_%E2%80%93_A_Worked_Example (2016-02-13)
    Open archived version from archive

  • Preparing an iOS 6 iPad App to use iCloud Storage - Techotopia
    leave the Bundle Seed menu set to Generate New and provide a bundle identifier formatted as follows com yourdomain yourappname In the above example com yourdomain will need to be replaced by the reverse URL of your domain name Click on Submit and note that the new app ID is now listed on the main App ID screen Figure 37 1 Note from the iCloud column of the table that this functionality is currently enabled This is the default setting In the event that iCloud support was not enabled by default or to disable the option click on the Configure link to display the Configure App ID screen Select the check box next to Enable for iCloud and click Done to commit the configuration change Figure 37 2 Creating and Installing an iCloud Enabled Provisioning Profile Having creating an iCloud enabled App ID the next step is to incorporate that ID into a provisioning profile Remaining in the iOS Provisioning Portal click on the Provisioning link and in the resulting screen click on the New Profile button Within the Create iOS Development Provisioning Profile screen name the new profile and select the development certificate to be used for the profile Using the App ID menu select the App ID created in the previous section followed by the devices on which the app is to be permitted to run before clicking on the Submit button If the new profile is listed as Pending in the main Provisioning screen simply use the browser reload button to refresh the page Once the profile is listed as active click on the Download button to save the mobileprovision file to your local system Once downloaded drag and drop the file onto the Xcode icon in the desktop dock to install it into the provisioning profiles library At this point the Xcode Organizer window should appear Connect your iPad to the system so that it is listed under DEVICES in the left hand panel of the Organizer window Select Provisioning Profiles from beneath the LIBRARY heading and drag and drop the new profile onto the Provisioning Profiles entry located beneath the iPad device under the DEVICES heading Once completed the provisioning profile is installed and ready to be used when developing an application Creating an iCloud Entitlements File Any applications that intend to use iCloud storage in any way must obtain entitlements appropriate to the iCloud features to be used These entitlements are placed into an entitlements file that is included in the Xcode project and built into the application at compile time If the application is intended to make use of iCloud document storage then the entitlements file must include a request for the com apple developer ubiquity container identifiers entitlement Similarly if the key value store is to be used then the com apple developer ubiquity kvstore identifier entitlement must be included Applications that require both forms of iCloud storage must include both entitlements The entitlements file is an XML file in which the

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

  • Managing Files using the iOS 6 UIDocument Class - Techotopia
    the contents of the iCloudStoreViewController h file Ctrl click on the Text View object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named textView Finally Ctrl click on the button object and drag the line to the area immediately beneath the newly created outlet in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method on the Touch Up Inside event configured to call a method named saveDocument Implementing the Application Data Structure So far we have created and partially implemented a UIDocument subclass named MyDocument and designed the user interface of the application together with corresponding actions and outlets As previously discussed the MyDocument class will require two methods that are responsible for interfacing between the MyDocument object instances the application s data structures Before we can implement these methods however we first need to implement the application data structure In the context of this application the data simply consists of the string entered by the user into the text view object Given the simplicity of this example we will declare the data structure such as it is within the MyDocument class where it can be easily accessed by the contentsForType and loadFromContents methods To implement the data structure albeit a single data value select the MyDocument h file and add a declaration for an NSString object import UIKit UIKit h interface MyDocument UIDocument property strong nonatomic NSString userText end Now that the data model is defined it is now time to complete the MyDocument class implementation Implementing the contentsForType Method The MyDocument class is a subclass of UIDocument When an instance of MyDocument is created and the appropriate method is called on that instance to save the application s data to a file the class makes a call to its contentsForType instance method It is the job of this method to collect the data to be stored in the document and to pass it back to the MyDocument object instance in the form of an NSData object The content of the NSData object will then be written to the document Whilst this may sound complicated most of the work is done for us by the parent UIDocument class All the method needs to do in fact is get the current value of the userText NSString object put it into an NSData object and return it Select the MyDocument m file and add the contentsForType method as follows id contentsForType NSString typeName error NSError autoreleasing outError return NSData dataWithBytes userText UTF8String length userText length Implementing the loadFromContents Method The loadFromContents instance method is called by an instance of MyDocument when the object is instructed to read the contents of a file This method is passed an NSData object containing the content of the document and is responsible for updating the application s internal data structure accordingly All this method needs to do therefore

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

  • Using iCloud Storage in an iPad iOS 6 Application - Techotopia
    necessary the next step is to append the document name document doc to the end of the ubuiquityURL path ubiquityURL ubiquityURL URLByAppendingPathComponent document doc The final task for the viewDidLoad method is to initiate a search in the application s iCloud storage area to find out if the document doc file already exists and to act accordingly subject to the result of the search The search is performed by calling the methods on an instance of the NSMetaDataQuery object This involves creating the object setting a predicate to indicate the files to search for and defining a ubiquitous search scope in other words instructing the object to search iCloud storage Once initiated the search is performed on a separate thread and issues a notification when completed For this reason it is also necessary to configure an observer to be notified when the search is finished The code to perform these tasks reads as follows metadataQuery NSMetadataQuery alloc init metadataQuery setPredicate NSPredicate predicateWithFormat K like document doc NSMetadataItemFSNameKey metadataQuery setSearchScopes NSArray arrayWithObjects NSMetadataQueryUbiquitousDocumentsScope nil NSNotificationCenter defaultCenter addObserver self selector selector metadataQueryDidFinishGathering name NSMetadataQueryDidFinishGatheringNotification object metadataQuery metadataQuery startQuery Once the metadataQuery startQuery method is called the search will run and trigger the metadataQueryDidFinishGathering method once the search is complete The next step therefore is to implement the metadataQueryDidFinishGathering method Before doing so however note that the viewDidLoad method is now complete and the full implementation should read as follows void viewDidLoad super viewDidLoad NSArray dirPaths NSSearchPathForDirectoriesInDomains NSDocumentDirectory NSUserDomainMask YES NSString docsDir dirPaths 0 NSString dataFile docsDir stringByAppendingPathComponent document doc documentURL NSURL fileURLWithPath dataFile NSFileManager filemgr NSFileManager defaultManager filemgr removeItemAtURL documentURL error nil ubiquityURL filemgr URLForUbiquityContainerIdentifier nil URLByAppendingPathComponent Documents if filemgr fileExistsAtPath ubiquityURL path NO filemgr createDirectoryAtURL ubiquityURL withIntermediateDirectories YES attributes nil error nil ubiquityURL ubiquityURL URLByAppendingPathComponent document doc Search for document in iCloud storage metadataQuery NSMetadataQuery alloc init metadataQuery setPredicate NSPredicate predicateWithFormat K like document doc NSMetadataItemFSNameKey metadataQuery setSearchScopes NSArray arrayWithObjects NSMetadataQueryUbiquitousDocumentsScope nil NSNotificationCenter defaultCenter addObserver self selector selector metadataQueryDidFinishGathering name NSMetadataQueryDidFinishGatheringNotification object metadataQuery metadataQuery startQuery Implementing the metadataQueryDidFinishGathering Method When the meta data query was triggered in the viewDidLoad method to search for documents in the application s iCloud storage area an observer was configured to call a method named metadataQueryDidFinishGathering when the initial search completed The next logical step is to implement this method The first task of the method is to identify the query object that caused this method to be called This object must then be used to disable any further query updates at this stage the document either exists or doesn t exist so there is nothing to be gained by receiving additional updates and stop the search It is also necessary to remove the observer that triggered the method call Combined these requirements result in the following code NSMetadataQuery query notification object query disableUpdates NSNotificationCenter defaultCenter removeObserver self name NSMetadataQueryDidFinishGatheringNotification object query query stopQuery Next the query method of the query object needs to be called to extract an array of documents located during the search

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



  •