didSelectRowAt有两个表Swift

时间:2017-07-21 19:42:21

标签: swift tableview

我有下面的didSelect行函数的代码,目标是让两个表根据触摸的表行执行不同的操作。第一部分工作正常。如果触摸了tableView 2,则打印行工作并取消选择行,但如果选择了tableView 3,则不会调用打印。两个tableViews在viewController中都有出口。

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if tableView == self.tableView2 {

            sorted = true

            print ("TEST")

            filteredDevices.removeAll()
            filteredOS.removeAll()
            filteredReported.removeAll()
            filteredMac.removeAll()
            filteredVersion.removeAll()



            let facility = defaults.object(forKey: "facility") as! String



        self.tableView.reloadData()

        tableView2.deselectRow(at: tableView2.indexPathForSelectedRow!, animated: true)

        }

        if tableView == tableView3 {

            sorted = true

            print ("test")

            filteredDevices.removeAll()
            filteredOS.removeAll()
            filteredReported.removeAll()
            filteredMac.removeAll()
            filteredVersion.removeAll()



            self.tableView.reloadData()
            print ("test")

            tableView3.deselectRow(at: tableView3.indexPathForSelectedRow!, animated: true)
        }



    }

1 个答案:

答案 0 :(得分:1)

您可能忘记在TableViewController中设置tableView3的委托。

// Generated Jul 16, 2017 9:14:14 AM by Hibernate Tools 4.0.0

import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Mstrgenstate generated by hbm2java
 */
@Entity
@Table(name = "MSTRGENSTATE", schema = "ORAAPPS")
public class Mstrgenstate implements java.io.Serializable {

    /**
     * serial item added as required
     */
    private static final long serialVersionUID = 3354389768807065484L;

    private BigDecimal stateid;
    private BigDecimal countryid;
    private String stateshort;
    private String statemed;
    private String statelong;

    public Mstrgenstate() {
    }

    public Mstrgenstate(BigDecimal stateid) {
        this.stateid = stateid;
    }

    public Mstrgenstate(BigDecimal stateid, BigDecimal countryid,
            String stateshort, String statemed, String statelong) {
        this.stateid = stateid;
        this.countryid = countryid;
        this.stateshort = stateshort;
        this.statemed = statemed;
        this.statelong = statelong;
    }

    @Id
    @Column(name = "STATEID", unique = true, nullable = false, precision = 22, scale = 0)
    public BigDecimal getStateid() {
        return this.stateid;
    }

    public void setStateid(BigDecimal stateid) {
        this.stateid = stateid;
    }

    @Column(name = "COUNTRYID", precision = 22, scale = 0)
    public BigDecimal getCountryid() {
        return this.countryid;
    }

    public void setCountryid(BigDecimal countryid) {
        this.countryid = countryid;
    }

    @Column(name = "STATESHORT", length = 3)
    public String getStateshort() {
        return this.stateshort;
    }

    public void setStateshort(String stateshort) {
        this.stateshort = stateshort;
    }

    @Column(name = "STATEMED", length = 15)
    public String getStatemed() {
        return this.statemed;
    }

    public void setStatemed(String statemed) {
        this.statemed = statemed;
    }

    @Column(name = "STATELONG", length = 30)
    public String getStatelong() {
        return this.statelong;
    }

    public void setStatelong(String statelong) {
        this.statelong = statelong;
    }

}

由于tableView2正在运行,因此您必须已经拥有类似于tableView2的行。只需为tableView3添加一个,你应该很好。