The iPhone developer's cookbook (4)

Source: Internet
Author: User

Uiview and uiwindow
The iPhone rule goes like this: one window, comment views. Metaphorically speaking, uiwindow is the TV set, and uiviews are the actors on your favorite show.

Uiviews are user interface building blocks. Every iPhone user interface is built from uiviews displayed within one uiwindow, which is a specialized kind of uiview.

The UI at the beginning of certain classes (like uiview) stands for user interface.

The iPhone offers two core classes that offer choices to users.
The uialertview class produces those blue pop-up windows you 've seen in other applications.
The second choice-based class is uiactionsheet, which offers menus that scroll up from the bottom of the screen. as a rule, use action sheets when you have a number of options to choose from and alert views when you are presenting just two or three choices at most.
Both these presentations are modal.

Here's a quick rundown of the major classes provided by cocoa touch and what each control offers:
Uibutton: In interface builder, buttons are called round rect buttons.
Uisegmentedcontrol
Uiswitch class provides a simple binary control in cocoa touch.
Uislider class lets users choose a value from a specified range by sliding an indicator along a horizontal bar.
Page controls let users move between pages, usually as part of a uiscrollview implementation. the uipagecontrol class offers a series of small dots (like the ones you see on the iPhone's home page) showing the current page and leader users navigate to the next or previous pages.
Uitextfields are a kind of control that let you enter text.
Uitableview class provides the most commonly used table style. Tables offer rows of information (provided by the uitableviewcell class), which users scroll through and can select.
Uipickerview class offers a kind of table, where users can select choices by scrolling individual wheels. A specialized version of this class is the uidatepicker.

Of all the iPhone bars, only the uitoolbar class is meant for direct use.

Uiactivityindicatorview offers a spinning-style wheel, which is shown during an ongoing task.
When you want to communicate progress to a user, user the uiprogressview class.

View controllers aren't views. they are abstract classes with no visual representation; only views offer visual canvases. instead, they help your views live in a larger application design environment. do not set a frame the way you wowould with a normal uiview. uiviews use initwithframe:; uiviewcontrollers user init.

Uiviewcontroller is the parent class for view controllers and the one you use to manage your primary views. the basic uiview controller class manages each primary view's life time from start to finish and takes into account the changes that the view must react to along the way.

Without a View Controller, your interface won't support automatic orientation updates. uiviewcontroller instances are responsible for setting up how a view looks and what subviews it displays. often they rely on loading that information from. XIB files. A variety of instance methods such as loadview and viewdidload let you add behavior while or after a View sets up.

The uiviewcontroller mediates between views and these external demands, allowing the view to change itself to meet these needs.

Any time you use a navigation-style project, you must assign it a Root View Controller. this is the view controller that lives at the top of the navigation tree. all other view controllers branch out from this one. the name of. XIB file and Its Class reflect this design necessity.

Whenever you use an image backdrop, always be sure to enable interactions. This little "gotcha" frequently snags developers who forget.

As you add more elements to your interface builder view, it becomes difficult to select the correct one by clicking on it. one handy tip is to control + Shift + click on any view in an interface builder edit window to display a list of all views stacked at that point. you can choose an item from that list to select it.

The control-drag shortcut cut creates connections.

One of the great things about cocoa touch is that you don't have to program entirely by hand or entirely using interface builder.

Whenever xcode finds a. XIB file whose name matches a class derived from uiviewcontroller, it automatically loads that. XIB when initializing an instance.

Cocoa touch lets you recover objects from any. XIB file by calling loadnibnamed: Owner: Options :. this returns an array of objects initialized from. XIB bundle, which you can then grab and use in your program.

The order of the items in. XIB file array mirrors the order of the items in interface builder's project window. since this. XIB contains exactly on top-level item, the Code coshould just as easily use objectatindex: 0 as lastobject.

Uiviewcontroller instances decide whether to respond to iPhone orientation by implementing the Optional shouldautorotatetointerfaceorientation: method. this method returns either yes or no, depending on whether you want to support autorotation to given orientation. to allow autorotation to all possible orientations, simply return YES.

Possible iPhone orientations passed to this method include
events
uideviceorientationportrait
events
uideviceorientationfaceup
uideviceorientationfacedown
of these orientations, only the portrait and landscape Varieties influence how a view autorotates.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.