1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

2  Understanding Interface Builder

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 )


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



Figure 1-7. An empty Single View Application running on iOS Simulator



Now find the file Understanding_Interface_BuilderViewController_iPhone.xib in your

project and click on it. Interface Builder will open up within Xcode and will display

your user interface to you. Now that you have IB open, select from Xcode menus the

option View and then Utilities, and finally select Show Object Library (Figure 1-8).



1.2 Understanding Interface Builder | 9



www.it-ebooks.info



Figure 1-8. UI Objects in the Object Library in Interface Builder



Now if you have a look at the Object Library, you can see that you have plenty of choice

as to what you want to put on your interface. This includes buttons, on/off switches,

progress bars, table views, etc. For now, drag and drop a button on your user interface.

As simple as that (Figure 1-9).



10 | Chapter 1: The Basics



www.it-ebooks.info



Figure 1-9. A button on a nib



Right after this, from the Xcode menus, select File and then Save to make sure your

Understanding_Interface_BuilderViewController_iPhone.xib is saved. Then go ahead

and run your app on iOS Simulator (Figure 1-10).



1.2 Understanding Interface Builder | 11



www.it-ebooks.info



Figure 1-10. A button on the UI of your app



You might be surprised, but for now that is all that we need to know about Interface

Builder.



See Also

XXX



12 | Chapter 1: The Basics



www.it-ebooks.info



1.3 Compiling iOS Apps

Problem

You have learned how to create an iOS app and wonder how it behaves.



Solution

Compile and run your iOS apps using Apple's latest compiler. Then test your app on

iOS Simulator and also, preferrably, on a device.



Discussion

Creating an iOS App can be categorized under the following tasks:

1.

2.

3.

4.

5.



Planning

Prototyping

Designing

Implementing and Testing

Delivering



During the implementation of an app, you will constantly need to run your app on a

simulator or on various devices to make sure it is consistent, adheres to the design

guidelines that you or your teammates created for this project, and most importantly,

is stable enough for the App Store.

Crashes provide one of the major reasons for app rejections in the Apple

App Store. Apps that are not stable and crash often are not good enough

for consumers and Apple is very likely to reject them. So always make

sure that you thoroughly test your apps on iOS Simulator and on devices.



When we write our code, as we will learn very soon, we need to make sure that what

we are writing is correct. The process by which Xcode changes our code into executable

instructions is called compilation. The compiler does the compilation. In Xcode, we use

various build commands to compile our apps:

Build for Running

Use this when you want to debug your applications on the simulator or on a device.

Debugging is the process by which you can find mistakes in your code.

Build for Testing

Use this build setting to run unit-tests that you've written for your apps. Unit tests,

in short, are a set of instructions that you provide to Xcode. Xcode will run these



1.3 Compiling iOS Apps | 13



www.it-ebooks.info



instructions before it makes the final build. These instructions have one purpose

only: to make sure that each part of the app you've written is in full working order.

Build for Profiling

If you want to test the performance of your app, use this setting. Profiling is the

process by which you can find bottlenecks, memory leaks, and other quality-related

issues not covered by unit testing.

Build for Archiving

When you are sure your app is production quality or simply want to distribute it

to testers, use this setting.

To compile your apps, in Xcode, simply select the Product menu item, choose Build

For, and then choose whichever build setting you believe is relevant to the task you

want to accomplish.

What do you think happens if you have an error in your code? In Recipe 1.1 we created

a simple Page-Based Application, so let's go back to that app. Now open the RootViewController.m file in your project and look for this code:

- (void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

}



Change this code to the following:

- (void)viewWillAppear:(BOOL)animated

{

[super nonExistantMethod];

[super viewWillAppear:animated];

}



If you now try to use Product menu, Build For, and then Build For Running, you will

get the following error from Xcode:

error: Automatic Reference Counting Issue: Receiver type 'UIViewController'

for instance message does not declare a method

with selector 'nonExistantMethod'



This is what the compiler is telling you: the code that you've written cannot be compiled

and translated to proper instructions to the CPU. In this particular case, this is because

the compiler doesn't understand what nonExistantMethod actually is. This illustrates a

good compiler that warns of and sometimes stops you from making mistakes that make

your apps unstable.



See Also

XXX



14 | Chapter 1: The Basics



www.it-ebooks.info



Xem Thêm
Tải bản đầy đủ (.pdf) (900 trang)

×