-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITableViewButtonVC.swift
94 lines (62 loc) · 3.15 KB
/
UITableViewButtonVC.swift
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// UITableViewButtonVC.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/16.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//
import UIKit
class UITableViewButtonViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var myItems:[String] = ["C", "C++", "C#", "D", "SmallTalk","Objective-C", "Swift", "Ruby", "Python", "Go", "PHP", "Java"];
var myTableView:UITableView = UITableView();
override func viewDidLoad() {
self.title = "UITableViewButton";
self.view.backgroundColor = UIColor.whiteColor();
super.viewDidLoad()
let barHeight: CGFloat = UIApplication.sharedApplication().statusBarFrame.size.height
let displayWidth: CGFloat = self.view.frame.width
let displayHeight: CGFloat = self.view.frame.height
myTableView.frame = CGRect(x: 0, y: 0, width: displayWidth, height: displayHeight - barHeight)
myTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "MyCell")
myTableView.dataSource = self
myTableView.delegate = self
self.view.addSubview(myTableView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Num: \(indexPath.row)")
print("Value: \(myItems[indexPath.row])")
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numberOfRowsInSection")
return myItems.count
}
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
print("canEditRowAtIndexPath")
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
print("commitEdittingStyle:\(editingStyle)")
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("cellForRowAtIndexPath")
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath)
cell.textLabel?.text = "\(myItems[indexPath.row])"
return cell
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let myShareButton: UITableViewRowAction = UITableViewRowAction(style: .Normal, title: "Share") { (action, index) -> Void in
tableView.editing = false
print("share")
}
myShareButton.backgroundColor = UIColor.blueColor()
let myArchiveButton: UITableViewRowAction = UITableViewRowAction(style: .Normal, title: "Archive") { (action, index) -> Void in
tableView.editing = false
print("archive")
}
myArchiveButton.backgroundColor = UIColor.redColor()
return [myShareButton, myArchiveButton]
}
}