Ios Swift UITableView:如何从所选单元格收集数据
我想知道使用UITableView时如何从上一页收集数据 这很难解释,所以我给你举个例子 苹果默认日历应用程序在新事件页面中具有此功能。 当您打开新的偶数页时,您将在“重复”字段中看到“永不”。要改变这一点,你需要点击“从不”,然后转到下一页,选择“每周”之类的内容。如果选择每周,它将返回到第一页,重复字段现在显示每周Ios Swift UITableView:如何从所选单元格收集数据,ios,swift,uitableview,segue,Ios,Swift,Uitableview,Segue,我想知道使用UITableView时如何从上一页收集数据 这很难解释,所以我给你举个例子 苹果默认日历应用程序在新事件页面中具有此功能。 当您打开新的偶数页时,您将在“重复”字段中看到“永不”。要改变这一点,你需要点击“从不”,然后转到下一页,选择“每周”之类的内容。如果选择每周,它将返回到第一页,重复字段现在显示每周 我想做一些类似的,但不知道如何设置这个。。。我的问题是,;我需要使用Segue吗?我是否需要为单元格使用UIExtField或UILabel?通过什么触发器传递数据?Mainvi
我想做一些类似的,但不知道如何设置这个。。。我的问题是,;我需要使用Segue吗?我是否需要为单元格使用UIExtField或UILabel?通过什么触发器传递数据?MainviewController添加以下代码
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// "SelectionSegue" is same as storyboard segue identifier
if segue.identifier == "SelectionSegue" {
(segue.destination as! SelectCategoryViewController).selectedCategoryValue = self.selectedCategoryLabel.text!
print(selectedCategoryLabel)
}
}
在序列图像板中设置序列标识符
SelectedTableView
var selectedCategoryValue:String = ""
var CategeryArray = ["Food","Travel","Shopping","Card","MyReserve","Game","Songs","Movies","Entertainment","Business","Education","Finance","Drink","Sports","Social","Lifestyle"]
//添加TableView委托和数据源方法
extension SelectCategoryViewController: UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return CategeryArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell")!
cell.textLabel?.text = self.CategeryArray[indexPath.row]
if self.CategeryArray[indexPath.row] == self.selectedCategoryValue {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
self.selectedCategoryValue = CategeryArray[indexPath.row]
self.tableView.reloadData()
}
}
我的观点是
NavigationController->Mainview->SelectedTableView欢迎使用stackoverflow,您发布了试用代码,以便我们可以帮助您解决问题一般来说,您要求在视图控制器之间传递数据。您不认为
tableView.cellForRow(at:indepath)?.accessoryType=.checkmark
在didSelectRowAt
方法中是不必要的吗?谢谢Ramprasathselvam!您能告诉我您在哪里声明“selectedCategoryLabel”吗?MainViewController“None”文本是selectedCategoryLabel@Riki_UThanks Ramprasathselvam!那么,我是否要将其作为标识符添加到故事板中?或者我应该声明为变量?您可以在storyboard@Riki_中添加标识符