swift - 单击静态表格单元格时可以从服务器获取数据吗?

标签 swift uitableview

单击静态表格单元格时可以从服务器获取数据吗?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = super.tableView(tableView, cellForRowAt: indexPath)
    if indexPath.section == 1 {
        if indexPath.row == 0{
            cell.textLabel?.text = firstDay
        } else if indexPath.row == 1{
            cell.textLable?.text = secondDay
        }... // It have 7 row and 7 days
    }

    return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.section == 1 && indexPath.row == 0{
        retrieveTime()
    }
}

我发布此格式来获取数据,如何获取所选单元格标签文本并将其放在参数(jobDate)上..?

func retrieveTime(){
    let param = ["action": "retrieve time", "job": ["crew_id": crewID, "jobDate": firstDay]] as [String : Any]
}

最佳答案

您可以在 didselect 方法中检索 jobDate 的值,然后将其作为参数传递给retrieveTime 方法。

例如:

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

    if indexPath.section == 1 && indexPath.row == 0{
      let selectedCell: UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

      jobDateValue = selectedCell.textLabel!.text! 
      retrieveTime(jobDateValue)
          }
     }

关于swift - 单击静态表格单元格时可以从服务器获取数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45951559/

相关文章:

ios - 如何使用动画创建新节并将行移动到该节

ios - 行 -1 或 NSUIntegerMax 由 -[UITableViewDelegate tableView :titleForDeleteConfirmationButtonForRowAtIndexPath:] 给出

ios - 请求非结构或联合中的成员 tableView

ios - 'NSInternalInconsistencyException',原因 : 'Could not load NIB in bundle: ...' with name

ios - 如何在 Xamarin.iOS 中将 DetailTextLabel 垂直居中放置在 UITableView 的单元格中?

ios - 使用 CoreData 将远程搜索结果与本地数据库连接起来

ios - 我怎样才能改变颜色/把东西放在我的 View Controller 的 View 后面(快速)?

Swift 函数语法分解

c# - 在 mac sierra 上捕获并更改键盘以模拟 neo2 键盘布局

ios - Swift UIView.animateWithDuration 在加载内容时消失