- Make an object conform to a protocol
- What are the pros and cons of open source?
http://www.ted.com/talks/angela_lee_duckworth_the_key_to_success_grit?language=en
http://rypress.com/tutorials/objective-c/protocols
https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/Protocol.html#//apple_ref/doc/uid/TP40008195-CH45-SW1
https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/Delegation.html
UIAlertView
http://code.tutsplus.com/tutorials/ios-sdk-working-with-uialertview-and-uialertviewdelegate--mobile-3159
- In
viewDidLoad
, create and show aUIAlertView
.- Make sure your view controller conforms to the UIAlertViewDelegate protocol
- Implement some UIAlertViewDelegate methods with NSLogs
UIAlertViewController
As of iOS 8, Apple introduced a new way to handle alerts,UIAlertController
.
- Create another alert using
UIAlertController
Notice that there is no delegate forUIAlertController
. What are some pros a cons to the new approach?
UITextField
- Add a
UITextField
to your storyboard.- Drag from your
UITextField
int your code, creating aproperty
in your view controller.- In
viewDidLoad
, set thedelegate
property of theUITextField
toself
(the view controller)- Make sure that your view controller class *conforms to the
UITextField
(<UITextFieldDelegate
)- Which method would you use to disable editing of the
UITextField
?- Add a
UISwitch
. Only allow editing when theUISwitch
is set toon
.- Implement the
textFieldDidEndEditing
method. What do you need to do to trigger this method (hint: first responder)?
UIPickerView https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIPickerViewDelegate_Protocol/index.html
https://developer.apple.com/library/ios/documentation/iPhone/Reference/UIPickerViewDataSource_Protocol/index.html#//apple_ref/occ/intf/UIPickerViewDataSource
- Add a
UIPickerView
to your storyboard.- Drag from your
UIPickerView
into your code, creating aproperty
in your view controller.- In
viewDidLoad
, set thedelegate
property of theUIPickerView
to beself
(the view controller)- In
viewDidLoad
, set thedataSource
property to beself
(the view controller)- Make sure that your view controller class *conforms to the
UIPickerViewDelegate
protocol and theUIPickerViewDataSource
protocol. (<UIPickerViewDelegate, UIPickerViewDataSource>
)- Implement the required methods to render and interact with the
UIPickerView
- Fun ensues
Roll your own
- Create a
UINavigationController
with aUITableViewController
as its root view controller.- Create a new class called
CQColorTableViewController
(subclass ofUITableViewController
) and change theUITableViewController
in the storyboard toCQColorTableViewController
.- In
CQColorTableViewController.m
add@property (nonatomic) NSMutableArray *colors;
- Implement the
UITableViewDataSource
methods so that there is 1 section and there is a row for every item in your array.- Head back into the storyboard.
- In the
UINavigationBar
of theUINavigationController
, add a+
to the top right.- Add a modal segue from the
+
button to a newUIViewController
- Make a new class called
CQColorPickerViewController
and change your newUIViewController
to aCQColorPickerViewController
- In your
CQColorPickerViewController
add 6 buttons. Make the button titles the names of some colors. List of colors
- Create an action for when a user taps on one of the buttons (drag from storyboard to view controller).
- In your new method, add code to dismiss the modal view controller
- Create a new Objective-C file. Make sure you choose protocol from the drop down. Name it
CQColorPickerViewControllerDelegate
- In
CQColorPickerViewControllerDelegate.h
, in between@protocol
and@end
, add one method:
- (void)colorPickerViewController:(CQColorPickerViewController *)viewController didPickColor:(UIColor *)color;
- Head over to
CQColorPickerViewController.h
. Create a new property:@property (nonatomic, weak) id<CQColorPickerViewControllerDelegate>delegate;
. This is creating a property of typeid
calleddelegate
. The stuff in the <> is saying that this object must conform to theCQColorPickerViewViewControllerDelegate
.
- In
CQColorTableViewController.m
, importCQColorPickerViewControllerDelegate
. MakeCQColorTableViewController
conform to theCQColorPickerViewControllerDelegate
protocol and implement the one method that we created,colorPickerViewController:didPickColor: