UIViewController
methods get called as follows:
-
viewDidLoad()
—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. This method is intended for initial setup. However, because views may be purged due to limited resources in an app, there is no guarantee that it will be called only once. -
viewWillAppear()
—Intended for any operations that you want always to occur before the view becomes visible. Because a view’s visibility may be toggled or obscured by other views, this method is always called immediately before the content view appears onscreen. -
viewDidAppear()
—Intended for any operations that you want to occur as soon as the view becomes visible, such as fetching data or showing an animation. Because a view’s visibility may be toggled or obscured by other views, this method is always called immediately after the content view appears onscreen.
A complementary set of teardown methods exists, as shown in the state transition diagram above.
(没明白,待更新)
UIImagePickerControllerDelegate
:
func imagePickerControllerDidCancel(picker: UIImagePickerController)
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
The first of these, imagePickerControllerDidCancel(_:)
, gets called when a user taps the image picker’s Cancel button. This method gives you a chance to dismiss the UIImagePickerController
(and optionally, do any necessary cleanup). Implement imagePickerControllerDidCancel(_:)
to do that. (imagePickerControllerDidCancel,当用户点击iamge picker的cancel按钮时,该方法被调用)
imagePickerController(_:didFinishPickingMediaWithInfo:)
, gets called when a user selects a photo. This method gives you a chance to do something with the image or images that a user selected from the picker.(imagePickerController,当用户选择一个图片时,该方法被调用)
UITableViewController
and its subclasses adopt the necessary protocols to make the table view controller both a data source (
UITableViewDataSource
protocol) and a delegate (
UITableViewDelegate
protocol) for its associated table view.
(table view需要两个重要的辅助:数据源和代理。默认情况下,UITableViewController
及其子类遵循两个协议,一个是UITableViewDataSource协议,即数据源协议;另一个是UITableViewDelegate协议,机代理协议)
A functioning table view requires three table view data source methods.
func numberOfSectionsInTableView(tableView: UITableView) -> Int
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
(numberOfSectionsInTableView()方法,指定table view需要显示几个section。tableView(_:numberOfRowsInSection:)方法,指定table view 在指定的section上显示多少row。tableView(_:cellForRowAtIndexPath:)方法,提供一个配置的cell显示在指定的row上。
)
prepareForSegue(_:sender:)
, and it gives you a chance to store data and do any necessary cleanup on the
source view controller
(the view controller that the segue is coming from).
(当一个segue被触发时,prepareForSegue(_:sender:)方法将被触发执行,可以在这个方法中添加数据存储等逻辑功能。source view controller是一个view controller,它的内容在segue开始时被显示出来)
prepareForSegue(_:sender:)
method is called before any segue gets executed.
tableView(_:commitEditingStyle:forRowAtIndexPath:):
This delegate method is in charge of managing the table rows when it’s in editing mode.
tableView(_:canEditRowAtIndexPath:):
support editing.