Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (24.65 MB, 900 trang )
3. In the New Project dialog (Figure 1-1), on the left, make sure the Application category is selected under the iOS main category. Then select Page-Based Application
on the right hand side and press the Next button.
4. You will now need to enter your product name (App Name) and your company
identifier. This uniquely identifies your product for your own company. Set your
product name to Creating a Simple iOS App in Xcode. The company identifier is
normally a domain name with the components reversed. My company name is
Pixolity, and therefore I will set the Company Name to com.pixolity as shown in
Figure 1-2. Leave the rest of the values in this screen just the way I've left them in
Figure 1-2 and press the Next button.
Figure 1-2. Setting the new project's settings
5. You will now be asked to save your project on a disk. Select your desired location
and press the Create button, as shown in Figure 1-3. Xcode will now create your
project files and the structure of your project.
1.1 Creating a Simple iOS App in Xcode | 3
www.it-ebooks.info
Figure 1-3. Saving a new iOS project on disk using Xcode
6. Now, before running your app, make sure you have unplugged any iPhones or
iPads/iPods that you have connected to your computer. The reason behind this is
that if a device is connected to your Mac, Xcode will try to run your apps on the
device instead of the simulator, and if you haven't configured your device for development, you might get blocked and not be able to run your apps.
7. From the dropdown on top left corner of Xcode, make sure iPhone Simulator or
iPad Simulator is selected. In this example, I will make sure iPad Simulator is selected, as shown in Figure 1-4.
4 | Chapter 1: The Basics
www.it-ebooks.info
Figure 1-4. Running your iOS App on iPad Simulator
8. Now that everything is ready, press the Command+Shift+R keys on your keyboard
or simply go to the Product menu and then press the Run button as shown in
Figure 1-5.
1.1 Creating a Simple iOS App in Xcode | 5
www.it-ebooks.info
Figure 1-5. The Run menu item in Xcode
Congratulations. Now you have a simple app running in iOS Simulator. As you saw,
there are various different iOS project templates that you can choose from (Figure 1-1). Here is a list of some of the handy project templates that you can use:
Master-Detail Application
This project template will set up a split view controller for your us. Split view
controllers are explained in Chapter 2, Implementing Controllers and Views.
6 | Chapter 1: The Basics
www.it-ebooks.info
Page-Based Application
This template will allow your app to have an iBooks user interface, where the user
will be able to flip through the pages that are drawn by the app. You'll learn more
about this in Chapter 2, Implementing Controllers and Views.
Empty Application
An empty application is simply made out of the most basic components that any
iOS app has. I use this template a lot to set up my iOS apps the way I like them to
be set up, without any preconfiguration by Xcode.
See Also
XXX
1.2 Understanding Interface Builder
Problem
You want to start designing a user interface for your iOS apps but don't want to waste
time coding.
Solution
Use Interface Builder.
Discussion
Interface Builder, or IB, is integrated into Xcode as a tool for creating a user interface
for your Mac and iOS apps. IB manipulates .xib files, which are called nib files to reflect
the file extension they had in past Apple products. A nib file is basically an XML file
that is managed by IB.
Let's go ahead and start using IB. To do this, first create an iOS App using the Single
View Application iOS Project template in Xcode. Follow the instructions in Recipe 1.1, but instead of Page-Based Application template (Figure 1-1), use the Single
View Application template and follow it to the last dialog to save your project to disk.
I've named the project Understanding Interface Builder.
Make sure your app is a Universal app, as shown in Figure 1-2.
After your project is created, the first thing you need to do is make sure it is going to
run on iPhone Simulator, as shown in Figure 1-6.
1.2 Understanding Interface Builder | 7
www.it-ebooks.info
Figure 1-6. Choosing to run your app on iPhone Simulator
Now press Command+Shift+R to run your application. You will then see the iOS Simulator showing your empty application, as shown in Figure 1-7.
8 | Chapter 1: The Basics
www.it-ebooks.info