UA-17470720-3

Jump to content


Photo
- - - - -

Programmatically Switching Tabs and popToRootViewController Turns Cell to Basic


  • Please log in to reply
7 replies to this topic

#1 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 10 January 2015 - 05:42 PM

Greetings Programs!

 

In my first tab, I have a Sites tableview and on the first time I select a cell, it switches to the second tab (categories) and displays the data from the web service using the custom cell as expected.

 

However, if I switch back to the first tab and select another (or same) site, it switches to the second tab as expected but this time the cells are now a basic cell with only the title.

 

I know there was this thread http://sensiblecocoa...c/360-poptoroot regarding a pop-to-root feature to be implemented in 2.1 but not sure where that lead to.

 

Am I popping correctly for STV? If not, how should I be doing it?

 

if let viewControllers = self.tabBarController?.viewControllers
{
	// Get the Forum tab bar's navigation controller.
	var navigationController = viewControllers[1] as UINavigationController
	navigationController.tabBarItem.enabled = true

	// Get the SCTableViewController.
	var view = navigationController.viewControllers[0] as CategoryViewController

	// Set the flag to reloadData.
	view.reloadData = true;

	// Set the selected site object containing the web service url used to replace the webServiceDef.baseUrl.
	view.currentSite = self.site
		
	// Switch to the second tab.
	self.tabBarController?.selectedIndex = 1

	// Go back to the main tableviewcontroller (Categories) of the tab.
	navigationController.popToRootViewControllerAnimated(false)
}

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 539 posts
  • LocationIreland
Reputation: 134
Popular

Posted 12 January 2015 - 11:11 PM

Hi wizgod,

 

I think the order of this is maybe causing issues here. Currently the order is:

 

Enable the tab.

Reload the data in the tabs tableview.

Set the site for the tableview in the tab.

Switch to the tab.

Pop to root in the tab. 

 

It would make more sense to me if you:

 

 

Pop to root in the tab. 

Set the site for the tableview in the tab.

Reload the data in the tabs tableview. (And reloadBoundValues for STV?)

Enable the tab.

Switch to the tab.

 

I'm using popToRootViewControllerAnimated in a couple of my STV apps and it's not causing any problems. Well iOS8 made the non animated pop look animated, but apart for that, no STV problems.


Cheers,

Dave

www.dgapps.ie

#3 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 13 January 2015 - 11:53 AM

Thanks Dave,

 

When I was flagging the view to reload data, it would also set up the tableviewmodel at the same time causing the issue.

 

// This is in viewWillAppear.
if reloadData == true
{
      reloadData = false

      // Moved this here.
      tableView.reloadData()
      tableViewModel.reloadBoundValues()

      // Moved this to viewDidLoad to run once.
      // displayView()
}

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 January 2015 - 09:08 AM

Hi Wg,

 

Depending on how your app is structured, it might be the case that STV is never getting the chance to actually save the values. Have you tried popping using [self dismissWithCancelValue:NO doneValue:YES] from within your SCTableViewController, instead of navigationController.popToRootViewControllerAnimated?


Edited by Tarek, 19 January 2015 - 09:08 AM.
Typo


#5 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 19 January 2015 - 09:42 AM

Hi Tarek!

 

Will that pop to the root view controller or just the parent view controller?

 

In my app, I am in the Sites tab and I am popping the Forums tab navigationController to the root Categories view controller when the user selects a site just before I switch to the Forums tab. The Forums tab segues are Categories -> Topics -> Posts -> Reply and it was easier just to pop to root than figuring out which was the active view controller and cascading up.

 

I keep thinking the way I'm switching isn't the best way; thoughts on a better process for switching tabs on didSelect?

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 January 2015 - 10:33 AM

Hi Wg,

 

I see what you're doing now, but I still can't understand how the cells are changing their type as you described. Are you able to provide a sample?



#7 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 19 January 2015 - 02:35 PM

Hi Tarek!

 

I believe it was because I was originally setting the objectsModel in viewWillAppear so on subsequent loads, the cell type would change. As long as I don't do that, all is fine.

 

var objectsModel = SCArrayOfObjectsModel(tableView: self.tableView)
objectsModel.enableSearchController = true
self.tableViewModel = objectsModel

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 January 2015 - 12:03 PM

Yes, you should definitely do all tableViewModel configuration in viewDidLoad.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users