var cv_arrayData: [String] = ["Home","Find People","Photos","Communities","Pages","What\'s Hot"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
}
return self.cv_arrayData.count
// let cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("SimpleCell")! as UITableViewCell
// cell.textLabel?.text = self.cv_arrayData[indexPath.row]
// return cell
// let cell:UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "SimpleCell")! as UITableViewCell
// cell.textLabel?.text = self.cv_arrayData[(indexPath as NSIndexPath).row]
// return cell
let cell = tableView.dequeueReusableCell(withIdentifier: "SimpleCell")
cell?.textLabel?.text = cv_arrayData[indexPath.row]
return cell!
@IBOutlet var vv_tableView: UITableView!
@IBAction func cf_tableAdd(_ sender: UIBarButtonItem) {
//cv_arrayData.append("New Item")
cv_arrayData.insert("New Item", at: 0)
vv_tableView.reloadData()
}
@IBAction func cf_tableDel(_ sender: UIBarButtonItem) {
if (cv_arrayData.count > 0) {
cv_arrayData.remove(at: 0)
vv_tableView.reloadData()
}
}
@IBAction func cf_tableReset(_ sender: UIBarButtonItem) {
cv_arrayData = ["Home","Find People","Photos","Communities","Pages","What\'s Hot"]
vv_tableView.reloadData()
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.rightBarButtonItem = self.editButtonItem
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
cv_arrayData.remove(at: (indexPath as NSIndexPath).row)
self.vv_tableView.reloadData()
}
}
// when edit button enabled and pressed, set move enabled
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let movedObject = self.cv_arrayData[sourceIndexPath.row]
cv_arrayData.remove(at: sourceIndexPath.row)
cv_arrayData.insert(movedObject, at: destinationIndexPath.row)
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCell.EditingStyle.delete {
cv_arrayData.remove(at: (indexPath as NSIndexPath).row)
self.vv_tableView.reloadData()
}
}
var cv_arrayData: [String] = ["iPad","Xoom","Playbook","TouchPad","Surface"]
var cv_arrayModel: [String] = ["iPad","Xoom","Playbook","TouchPad","Surface"]
var cv_arrayOS: [String] = ["iOS","Android","BlackBerry","WebOS","Windows"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.cv_arrayModel.count;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SimpleCell")
cell?.textLabel?.text = cv_arrayModel[indexPath.row]
cell?.detailTextLabel?.text = cv_arrayOS[indexPath.row]
return cell!
}
var cv_arrayModel: [String] = ["iPad","Xoom","Playbook","TouchPad","Surface"]
var cv_arrayOS: [String] = ["iOS","Android","BlackBerry","WebOS","Windows"]
var cv_arrayImg: [String] = ["01-ipad.png","02-xoom.png","03-playbook.png","04-touchpad.png", "05-surface.png"]
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SimpleCell")
cell?.textLabel?.text = cv_arrayModel[indexPath.row]
cell?.detailTextLabel?.text = cv_arrayOS[indexPath.row]
cell?.imageView?.image = UIImage(named: cv_arrayImg[indexPath.row])
return cell!
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 96
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let rowValue = cv_arrayModel[(indexPath as NSIndexPath).row]
let message = "You selected \(rowValue)"
let controller = UIAlertController(title: "Row Selected", message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "Yes I Did", style: .default, handler: nil)
controller.addAction(action)
present(controller, animated: true, completion: nil)
}
if (indexPath.row % 2 == 1) {
cell?.backgroundColor = UIColor.lightGray
}