What to call didSelectRowAtIndexPath before preparation?

I am making an iOS application that is the base of a table. Here is what I want to do. Tableview1 -> Tableview2 As soon as I select one of tableCell, a new tableView2 will be shown. I would like to highlight the cell until a new tableView appears. However, hilight is so slow due to loading new tableView data. I looked at that. The reason that prepareForSegue is called before didSelectRowAtIndexPath .

Then could you tell me what to call didSelectRowAtIndexPath before prepareForSegue ?

Or tell me how to set up a table cell when selecting a cell.

All the best.

+7
source share
4 answers

You create two different ways to do this.

1 - The first alternative - use only storyboards and prepare ForSegue:

Connect your prototype cell to the second view manager in the storyboard (the connection should start from the cell and end on the second view manager). In this case, you should use only the prepareForSegue method, not didSelectRowAtIndexPath. The second VC is automatically activated after the prepareForSegue command.

2 - The second alternative is use didSelectRowAtIndexPath:

You use didSelectRowAtIndexPath only if you connect segue from the first view controller (and not from the cell) to the second view manager. At the end of the didSelectRowAtIndexPath method, you must call performSegue.

+20
source
  • Make segue for controller-> controller
  • load data in didselectrowatindexpath file
  • When it is done β†’ do your segue
+1
source

You need the following function. It will be called before the prepared ForSegue. First you need to define var in your class, and then set it in this function, as shown below:

 var selectedIndexPath: NSIndexPath = NSIndexPath() override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? { selectedIndexPath = indexPath return indexPath } 

Then, finally, you can use this value in the readyForSegue function

+1
source

Here's how you should configure your view controllers:

  • When the View Table Table 1 controller chassis loads, load the Table View 1 data.
  • In tableView:didSelectRowAtIndexPath: called, disable segue using performSegue:
  • When the View Table Table 2 controller enclosure loads, download the data for Table View 2.

It seems like you can download data for Table View 2 prematurely - that’s why you see the lag. Since you associate the main stream with data loading, the user interface does not have the ability to update and display blue.

If you load data into the viewDidLoad method, you will avoid costly loads when the user selects a table view cell. You should only point the view controller to execute the segue command on the detail view controller in the tableView:didSelectRowAtIndexPath: method.

0
source

All Articles