I need swift code in my ViewController one table view, label, AddButton. In tableview 8 customcells are there, in each cell one label,(-, +) buttons are there. If I press '+' label value must increase while if I press '-' label value decrease, same way happen to each and every cell. Finally, if I press AddButton the total must be added and it displays in a label in viewcontroller Thanks, InAdvance. image in viewController tableview methods
@IBOutlet var tableviewObj: UITableView!
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 8
}
public func numberOfSections(in tableView: UITableView) -> Int // Default is 1 if not implemented
{
return 1
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.row == 0 {
let cell:firstTableViewCell = tableView.dequeueReusableCell(withIdentifier: "first") as! firstTableViewCell
return cell
}
else if indexPath.row == 1 {
let cell:secondTableViewCell = tableView.dequeueReusableCell(withIdentifier: "second") as! secondTableViewCell
return cell
}
else if indexPath.row == 2 {
let cell:thirdTableViewCell = tableView.dequeueReusableCell(withIdentifier: "third") as! thirdTableViewCell
return cell
}
else if indexPath.row == 3 {
let cell:fourthTableViewCell = tableView.dequeueReusableCell(withIdentifier: "fourth") as! fourthTableViewCell
return cell
}
else if indexPath.row == 4 {
let cell:fifthTableViewCell = tableView.dequeueReusableCell(withIdentifier: "fifth") as! fifthTableViewCell
return cell
}
else if indexPath.row == 5 {
let cell:sixthTableViewCell = tableView.dequeueReusableCell(withIdentifier: "sixth") as! sixthTableViewCell
return cell
}
else if indexPath.row == 6 {
let cell:seventhTableViewCell = tableView.dequeueReusableCell(withIdentifier: "seven") as! seventhTableViewCell
return cell
}else {
let cell:eighthTableViewCell = tableView.dequeueReusableCell(withIdentifier: "eight") as! eighthTableViewCell
return cell
}
}
@IBOutlet var labelObj: UILabel!
@IBAction func Total(_ sender: Any) {
// i need code here
}
class firstTableViewCell: UITableViewCell {
@IBOutlet var labelObj: UILabel!
var cur = 0
var str = ""
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
@IBAction func Minus(_ sender: Any) {
if (self.labelObj.text == "1") {
self.labelObj.text = String( 1)
}else
{
cur = Int(labelObj.text!)!
self.labelObj.text = String(cur - 1)
str = self.labelObj.text!
print(str)
}
}
@IBAction func Add(_ sender: Any) {
cur = Int(labelObj.text!)!
self.labelObj.text = String(cur + 1)
str = self.labelObj.text!
print(str)
}