Use button from another class?

I have two Table Views in one View Controller. One of the Table Views is using a custom cell.

I have created a separate custom class for the two Table Views. I connected the button to the custom class from IB. How do I use the button in the Main View Controller?


Custom Class:

import UIKit
class MainTableViewCell : UITableViewCell
    @IBOutlet weak var refMainCell: UILabel!


class SubTableViewCell : UITableViewCell
    var counter: Int = 0
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!
    @IBAction func minusButton(_ sender: UIButton)
        counter -= 1
    @IBAction func plussButton(_ sender: UIButton)
        counter += 1
        //I want to use this button to add to array
    @IBOutlet weak var counterLabel: UILabel!


Set up in Main View Controller:


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
       if (tableView == MainTableView)
            let cell = tableView.dequeueReusableCell(withIdentifier: "MainCell", for: indexPath) as! MainTableViewCell
            cell.refMainCell.text = mainArray[indexPath.row]
            cell.detailTextLabel?.text = subtitleArray[indexPath.row]
            cell.accessoryType = .disclosureIndicator
            return cell
            let cell: UITableViewCell
            cell = tableView.dequeueReusableCell(withIdentifier: "SubCell", for: indexPath)
            if let customCell = cell as? SubTableViewCell
                customCell.label.text = subArray[indexPath.section].SectionObjects[indexPath.row]
                customCell.SubtitleLabel.text = subArray[indexPath.section].subtitleArray[indexPath.row]
                customCell.counterLabel.text = String (customCell.counter)
                if let tbc = self.tabBarController as? TabBarController {
                    //I want customCell.plussButton(UIButton) to append to the myInformation array like this:
            return cell


How can I get the button to appen to the myInformation array?



Powered by WPeMatico


You may also like...

Comments are closed.