What is the difference between outlet connection and action connection?
ios, xcode
Solution
Outlet and Action are ways (or connection/intermediary) by which a ViewController will interact with its View. Though both of them may look similar during initial days of iOS acquaintance but they serve different purpose:
Outlet: `ViewController talks to View by using Outlet`. Any object (UILabel, UIButton, UIImage, UIView etc) in View can have an Outlet connection to ViewController. Outlet is used as `@property` in ViewController which means that: - you can set something (like Update UILabel's text, Set background image of a UIView etc.) of an object by using outlet. - you can get something from an object (like current value of UIStepper, current font size of a NSAttributedString etc.)
Action: `View pass on messages about view to ViewController by using Action` (Or in technical terms ViewController set itself as `Target` for any `Action` in View). Action is a `Method` in ViewController (unlike Outlet which is `@property` in ViewController). Whenever something (any `Event`) happens to an object (like UIbutton is tapped) then Action pass on message to ViewController. Action (or Action method) can do something after receiving the message. Note: Action can be set only by UIControl's child object; means you can't set Action for UILabel, UIView etc.
Where\When to use Outlet or Action: During initial days of iOS acquaintance its perfectly normal to get confused between Action and Outlet and their usages. There are few small things (like getting text/title of a button) that can be done by both Outlet and Action but otherwise they are very different. Keep above points in mind while using one or other.
Problem
When I try to create a connection between xib and the file's owner, there are several types to choose from: - outlet connection - action connection - outlet collection connection What are the differences between all of those?