forked from sachinkesiraju/SwiftExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableViewController.swift
More file actions
97 lines (74 loc) · 3.01 KB
/
Copy pathTableViewController.swift
File metadata and controls
97 lines (74 loc) · 3.01 KB
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
94
95
96
97
//
// TableViewController.swift
// SwiftExample
//
// Created by Sachin Kesiraju on 6/3/14.
// Copyright (c) 2014 Sachin Kesiraju. All rights reserved.
//
import UIKit
class TableViewController: UITableViewController {
var tableArray:NSMutableArray = ["Swift", "Objective -C", "Python", "Java", "Ruby"]
override init(style: UITableViewStyle) {
super.init(style: style)
// Custom initialization
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Table View"
}
override func viewDidAppear(animated: Bool)
{
self.tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//#pragma mark - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return tableArray.count;
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
{
return true;
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
if(editingStyle == UITableViewCellEditingStyle.Delete)
{
tableArray.removeObjectAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
tableView.reloadData()
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = tableArray.objectAtIndex(indexPath.row) as! String
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
self.showAlert(tableArray.objectAtIndex(indexPath.row) as! NSString, rowToUseInAlert: indexPath.row)
}
//#pragma mark - UIAlertView delegate methods
func alertView(alertView: UIAlertView!, didDismissWithButtonIndex buttonIndex: Int) {
NSLog("Did dismiss button: %d", buttonIndex)
}
// Function to init a UIAlertView and show it
func showAlert(rowTitle:NSString, rowToUseInAlert: Int) {
var alert = UIAlertView()
alert.delegate = self
alert.title = rowTitle as String
alert.message = "You selected row \(rowToUseInAlert)"
alert.addButtonWithTitle("OK")
alert.show()
}
}