简体   繁体   中英

Change UITableViewCell's properties from the presented view

In a UITableViewCell on a button click, I do

EditPostViewController.type = "post"
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "editPost") as! EditPostViewController
top?.present(nextViewController, animated: true, completion: nil)

To go to EditPostViewController. Now in this EditPostViewController, I have a textbox, the user edits and the clicks the back button.

How can I edit the variables of that particular UITableViewCell from EditPostViewController after some button click event?

So I tried taking the variable of self in the UITableViewCell and then editing it in the EditPostViewController like

EditPostViewController.instance = self

And in EditPostViewController

EditPostViewController.instance.label.text = "something"

This doesn't work. This says that UITableViewCell has no property named instance. Any idea how can I edit the value of this label in the UITableViewCell from EditPostViewController?

You can take a look at unwind segues to solve your problem (there are other ways as well).

The iOS developer jump right in page found here can show you detailed instructions on how to get it going: https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementEditAndDeleteBehavior.html

Basically what you need to do is obtain the target view controller from the EditPostViewController during the unwind segue and update it's datsource. The unwind segue is an @IBAction defined on the "Back" button of the EditPostViewController (or any other button for that matter).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM