The UIKit framework provides a great deal of your iPhone application’s basic functionality. As you develop your iPhone app, you customize the behavior of the UIKit framework by using subclassing, target-action, and delegation, but one challenge facing new developers is determining which of these mechanisms to use when. These tips can help you decide:
>
>
When to Use Subclassing in iPhone App Development
Subclassing is one of the mechanisms you use to customize behaviors while you're developing your iPhone application. Subclassing involves two stages: (1) creating a new class, called a subclass, that inherits properties from another (super) class and then (2) adding properties as needed for your iPhone application. In general, you’ll want to subclass
UIView, to create your (more complex) content views, which you may fill with controls, graphics, or the like.
UIViewController, to manage the content views and connect it to the model.
NSObject, to create Model views and delegates.
>
>
>
Knowing the Target-Action Patterns for iPhone App Development
Following are the Target-Action patterns that you use when programming iPhone applications. You generally will specify the target as the view controller (which you’ll have already subclassed) because it controls the view in which these controls reside.
UITabBarItem (for items on the tab bar)
UIBarButtonItem (for items on the navigation bar and tool bar)
UIButton
UIDatePicker
UIPageControl
UISegmentedControl
UITextField
UISlider
UISwitch
>
>
>
Using Delegates with Views and Other Classes
When you create iPhone applications, you use delegates to implement application-specific behavior for generic views or classes. The table includes all known available delegates used in iPhone application development, though others may be possible. Exceptions to when you need to use a delegate are shown in the Special Use column.
Class | Delegate(s) Protocol | Special Use |
---|---|---|
ABPeoplePickerNavigationController ABNewPersonViewController ABNewPersonViewController ABUnknownPersonViewController | ABPeoplePickerNavigationControllerDelegate ABNewPersonViewControllerDelegate ABNewPersonViewControllerDelegate ABUnknownPersonViewControllerDelegate | |
AVAudioRecorder | AVAudioRecorderDelegate | |
AVAudioSession | AVAudioSessionDelegate | |
CAAnimation | None | |
CAAnimationGroup | None | |
CALayer | None | |
CLLocationManager | CLLocationManagerDelegate | |
EAAccessory | EAAccessoryDelegate | |
GKSession | GKSessionDelegate | |
GKPeerPickerController | GKPeerPickerControllerDelegate | |
NSError | NSErrorRecoveryAttempting | |
MKMapView | MKAnnotation | |
MKMapViewDelegate | ||
MkReverseGeocoder | MKReverseGeocoderDelegate | |
NSNetService NSNetServiceBrowser | NSNetServiceDelegate NSNetServiceBrowserDelegate | |
NSStream | NSStreamDelegate | |
NSPort NSMachPort | NSPortDelegate NSMachPortDelegate | |
NSFetchedResultsController | NSFetchedResultsControllerDelegate | |
NSKeyedArchiver NSKeyedUnarchiver | NSKeyedArchiverDelegate NSKeyedUnarchiverDelegate | |
NSURLConnection | None | |
MFMailComposeViewController | MFMailComposeViewControllerDelegate | |
SKRequest SKProductsRequest | SKRequestDelegate SKProductsRequestDelegate | |
UIAccelerometer | UIAccelerometerDelegate | |
UIActionSheet | UIActionSheetDelegate | |
UIAlertView | UIAlertViewDelegate | |
UIApplication | UIApplicationDelegate | Also used for push notifications |
UIImagePicker | UIImagePickerControllerDelegate | |
UINavigationBar | UINavigationBarDelegate | To push or pop view controllers |
UIPickerView | UIPickerViewDataSource | |
UIPickerViewDelegate | ||
UIResponder | UIResponderStandardEditActions | Support for Copy, Paste, and Select |
UIScrollView | UIScrollViewDelegate | Under some circumstances |
UISearchDisplayController | UISearchDisplayDelegate | |
UISearchBar | UISearchBarDelegate | |
UITabBar | UITabBarControllerDelegate | To customize a tab bar |
UITableView | UITableViewDataSource | |
UITableViewDelegate | ||
UITextField | UITextFieldDelegate | To put away the keyboard |
UITextView | UITextViewDelegate | To examine text being edited |
UISearchBar | UISearchBarDelegate | |
UIWebView | UIWebViewDelegate | |
MPMediaPickerController | MPMediaPickerControllerDelegate | |
NSXMLParser | NSXMLParserDelegate |
>
>
>
Using Objective-C Operators
Objective-C operators, like those in other programming languages, let you perform operations on variables (hence the name). Objective-C provides many operators, and keeping track of all of them can be difficult as you program your iPhone app. Use the following tables to jog your memory as to which operator accomplishes what task.
Operator | What It Does |
---|---|
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
% | Modulo |
Operator | What It Does |
---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Operator | What It Does |
---|---|
! | NOT |
&& | Logical AND |
|| | Logical OR |
Operator | What It Does |
---|---|
+= | Addition |
-= | Subtraction |
*= | Multiplication |
\/= | Division |
\%= | Modulo |
&= | Bitwise AND |
|= | Bitwise Inclusive OR |
^= | Exclusive OR |
<<= | Shift Left |
>>= | Shift Right |
Operator | What It Does |
---|---|
++ | Addition |
-- | Subtraction |
*= | Multiplication |
/= | Division |
%= | Modulo |
&= | Bitwise AND |
|= | Bitwise Inclusive OR |
^= | Exclusive OR |
<<= | Shift Left |
>>= | Shift Right |
Operator | What It Does |
---|---|
& | Bitwise AND |
| | Bitwise Inclusive OR |
^ | Exclusive OR |
~ | Unary complement (bit inversion) |
<< | Shift Left |
>> | Shift Right |
Operator | What It Does |
---|---|
() | Cast |
, | Comma |
Sizeof() | Size of |
? : | Conditional |
& | Address |
* | Indirection |
>
>
dummies
Source:http://www.dummies.com/how-to/content/iphone-application-development-allinone-for-dummie.html
No comments:
Post a Comment