【发布时间】:2015-11-30 17:39:08
【问题描述】:
简短的版本是:
在模态展示和解雇另一个 VC 期间,一个 VC 变量的值是否保持不变?当第二个 VC 被解散时,原始 VC 的变量是否仍然等于它们最后的值?
详情(如果需要)
我有一个 viewController,其中选择了一个表格单元格。然后将该单元格的内容拉出并传递给编辑器视图控制器,如下所示:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//Segue to mainVC editor, for editing action
if (segue.identifier == "modalToEditor") && passingEdit == true {
//Assign selection to a variable 'currentCell'
let indexPath = tableView.indexPathForSelectedRow;
let currentCell = tableView.cellForRowAtIndexPath(indexPath!) as! CustomTableViewCell;
//Set cell text into variables to pass to editor
let cellNameForEdit = currentCell.nameLabel!.text
let cellDescForEdit = currentCell.descLabel.text
//Pass values to EditorView
let editorVC = segue.destinationViewController as! EditorView;
editorVC.namePassed = cellNameForEdit
editorVC.descPassed = cellDescForEdit
editorVC.indexOfTap = indexPath
editorVC.currentListEntity = currentListEntity
现在,在第二个/编辑器视图控制器中,用户可以点击一个按钮,要求移动单元格。 “移动屏幕”是一个不同的/第三个 VC。我想知道的是,我可以解雇编辑并期望原始 VC 记住最后选择的单元格吗?
- 如果它会记住,那么我假设我可以将它传递给第三个/移动 VC。
- 如果原来的 VC 单元变量不能保存最后一个单元,我必须想办法让它记住!可能是全局变量?
追加编辑以显示 cellForRowAtIndexPath
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Setup variables
let cellIdentifier = "BasicCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! CustomTableViewCell
//Make sure the row heights adjust properly
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 80.0
//Create normal cells except when last cell
if indexPath.row < taskList_Cntxt.count {
let task = taskList_Cntxt[indexPath.row]
//Create table cell with values from Core Data attribute lists
cell.nameLabel!.text = task.valueForKey("name") as? String
cell.descLabel!.text = task.valueForKey("desc") as? String
//Related to running TaskActions: Empty block function passed from custom cell VC
cell.doWork = {
() -> Void in
self.doStuff(cell)
}
}
【问题讨论】:
-
考虑复制粘贴代码而不是发布屏幕截图。
标签: ios swift segue tableviewcell