IOS 学习笔记
iOS学习笔记
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier{
case History.SegueIdentifier:
if let tvc = segue.destinationViewController as? TextViewController
{
if let ppc = tvc.popoverPresentationController{
ppc.delegate = self
}
tvc.text = "\(diagnostircHistory)"
}
default: break
}
}
}
|
- 对于一些功能组件,为了实现其方法,首先需要为其设置一个代理(类)。该类需要继承该组件指定的特点协议,通过实现协议中的方法实现组件方法。例如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| class DiagnosedHappinewwViewController: HappinessViewController,UIPopoverPresentationControllerDelegate
{
override var happiness: Int{
didSet {
diagnostircHistory += [happiness]
}
}
//
private let defaults = NSUserDefaults.standardUserDefaults()
var diagnostircHistory:[Int]{
get {return defaults.objectForKey(History.DefaultsKey) as? [Int] ?? [] }
set {defaults.setObject(newValue, forKey: History.DefaultsKey) }
}
private struct History {
static let SegueIdentifier = "Show Diagnostic History"
static let DefaultsKey = "DiagnosedHappinessViewController.History"
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
switch identifier{
case History.SegueIdentifier:
if let tvc = segue.destinationViewController as? TextViewController
{
if let ppc = tvc.popoverPresentationController{
ppc.delegate = self
}
tvc.text = "\(diagnostircHistory)"
}
default: break
}
}
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!, traitCollection: UITraitCollection!) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
}
|