Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
- @IBOutlet weak var myTable: UITableView!
- @IBOutlet weak var lblMonHoc: UILabel!
- @IBOutlet weak var tfInput: UITextField!
- @IBAction func Add(sender: AnyObject) {
- mangMonHoc.append(tfInput.text!)
- myTable.reloadData()
- }
- @IBAction func EditButton(sender: AnyObject) {
- myTable.editing = !myTable.editing
- }
- var mangMonHoc:[String] = ["iOS", "Android" ]
- override func viewDidLoad() {
- super.viewDidLoad()
- myTable.dataSource = self
- myTable.delegate = self
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func numberOfSectionsInTableView(tableView: UITableView) -> Int {
- return 1
- }
- func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return mangMonHoc.count
- }
- func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
- cell.textLabel?.text = mangMonHoc[indexPath.row]
- return cell
- }
- func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
- print("Click " + String(indexPath.row))
- lblMonHoc.text = mangMonHoc[indexPath.row]
- }
- func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
- if editingStyle == UITableViewCellEditingStyle.Delete {
- mangMonHoc.removeAtIndex(indexPath.row)
- myTable.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement