如何获得第一个表视图的索引路径.使用swift3,xcode8在第二个表视图中使用它



我在项目中有两个表视图,任何一个都可以帮助我获取索引路径。第一个表视图的路程,这是在第二个表视图中使用的主表主表的子表。

这是我的维护。

    import UIKit
    class MainTableViewController: UITableViewController {

var  womenArray = [women]()
var data : [String] = []
let backendless = Backendless()
override func viewDidLoad() {
    super.viewDidLoad()
    data = ["1","2","3","4","5"]
}
override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return data.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

    cell.textLabel?.text = data[indexPath.row]
    return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.womenArray.removeAll()
    if (indexPath.row == 0) {
        let whereClause = "Desc = 'test'"
        let dataQuery = BackendlessDataQuery()
        dataQuery.queryOptions.pageSize=50
        dataQuery.whereClause = whereClause
        backendless.data.of(women.ofClass()).find(dataQuery,response: {(result: BackendlessCollection?) -> Void in

            let data = result?.getCurrentPage()
            for obj in data! as! [women] {
                self.womenArray.append(obj)
            }
let SubWomenView: WomenSubTableViewController = self.storyboard!.instantiateViewController(withIdentifier: "subwomen") as! WomenSubTableViewController
SubWomenView.subWomenArray = self.womenArray
self.navigationController?.pushViewController(SubWomenView, animated: true)

},
error: { (fault: Fault?) -> Void in
 print(fault)
 let alert = UIAlertController(title: "info", message:"يرجى الاتصال بالانترنيت", preferredStyle: .alert)
   alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in

     })
self.present(alert, animated: true){}

        })

    }else if indexPath.row == 1{
        let whereClause = "Desc = 'test2'"
        let dataQuery = BackendlessDataQuery()
        dataQuery.queryOptions.pageSize=50
        dataQuery.whereClause = whereClause
        backendless.data.of(women.ofClass()).find(dataQuery,response: {(result: BackendlessCollection?) -> Void in

            let data = result?.getCurrentPage()
            for obj in data! as! [women] {
                self.womenArray.append(obj)
            }
let SubWomenView: WomenSubTableViewController = self.storyboard!.instantiateViewController(withIdentifier: "subwomen") as! WomenSubTableViewController
SubWomenView.subWomenArray = self.womenArray
self.navigationController?.pushViewController(SubWomenView, animated: true)

            },
  error: { (fault: Fault?) -> Void in

let alert = UIAlertController(title: "info", message:"يرجى الاتصال بالانترنيت", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in

    })
self.present(alert, animated: true){}

    })

     }
      }
   }

这是我的款项。

 import UIKit
 class SubTableViewController: UITableViewController {
var subWomenArray = [women]()

  let backendless = Backendless()
override func viewDidLoad() {
    super.viewDidLoad()

        }
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return subWomenArray.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? WomenSubCell{
        let ImgURL = URL(string : self.subWomenArray[(indexPath as NSIndexPath).row].ImgURL!)
        cell.WomenImgView.sd_setImage(with: ImgURL)
        return cell
    }else{
        let cell = WomenSubCell()
        let ImgURL = URL(string : self.subWomenArray [(indexPath as NSIndexPath).row].ImgURL)
        cell.WomenImgView.sd_setImage(with: ImgURL)

        return cell
    }

    }


     }

您可以在子表视图上创建一个属性,并在下行中分配数组时将indexpath的值分配给它:

subwomenview.subwomenarray = self.womenarray

也许使用元组更容易理解。subwomenview.subwomenarray =(index.row,self.womenarray)

在subtableview中,

var subwomenarray:(int,[women])

然后subwomenarray.1参考您的[women]

相关内容

  • 没有找到相关文章

最新更新