Last active
August 29, 2015 14:02
-
-
Save MooseV2/01c7e41b759b9ff913b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { | |
@IBOutlet var appsTableView : UITableView | |
@IBOutlet var sliderBar : UISlider | |
let tableCountRange = 2..8 //Constant: min 2, max 15 | |
var tableData = Double[]() | |
var selectedItem : Int = -1 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
//TABLEVIEW | |
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { | |
return tableData.count | |
} | |
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! | |
{ | |
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell") | |
cell.text = String(tableData[indexPath.row]) | |
cell.detailTextLabel.text = "Row #\(indexPath.row + 1)" //+1 because rows are 0-based | |
return cell | |
} | |
func tableView(tableView: UITableView!, shouldHighlightRowAtIndexPath indexPath: NSIndexPath!) -> Bool { | |
selectedItem = indexPath.row | |
sliderBar.value = CFloat(tableData[selectedItem]) | |
return true //Sending false here disallows highlighting (selecting) of item | |
} | |
//IBACTIONS | |
@IBAction func addItem(button : UIButton!) { | |
if (tableData.count < tableCountRange.endIndex) { | |
tableData.append(0) | |
} | |
appsTableView.reloadData() | |
} | |
@IBAction func remItem(button: UIButton!) { | |
if (tableData.count > tableCountRange.startIndex) { | |
tableData.removeLast() | |
} | |
appsTableView.reloadData() | |
} | |
@IBAction func sliderChange(slider : UISlider) { | |
if (selectedItem <= tableData.count && selectedItem >= 0) { | |
tableData[selectedItem] = Double(slider.value) | |
} | |
appsTableView.reloadData() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment