UA-17470720-3

Jump to content


Photo
- - - - -

Use or Pass PropertyDefinition Actions in/to DataDefinitions When Pushing View Controller


  • Please log in to reply
5 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 26 March 2015 - 08:43 PM

Greetings Programs!

 

No doubt you've read my previous post about my pushing view controllers with entitydefs of properties in detail views.

 

The annoyance I am having right now is that the pushed view controller does not have the actions on it that normally would have been placed had one gotten to it via the detail view.

 

childEntityDef: child

objectivesPropertyDef: child.objectives (array of objects)

objectiveEntityDef: objective

 

So the objectivesPropertyDef has actions for the objectiveEntityDef view controller; when going directly to objectiveEntityDef, custom cells, detail (model/viewcontroller) actions don't exist and I have to duplicate them on the pushed view controller.

 

I don't currently see any way to do this but is it possible to place those actions on the entityDef? Understanding that the SCDataDefinition may not actually be designed for this and it is not possible via it, is there any other way I might be able to do what I need? A subclass perhaps, but how?

 

Thanks!

 

Wg


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


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 March 2015 - 08:52 AM

Hi Wg,

 

Could you please give some examples of these missing actions? I am not sure I am following here.



#3 wizgod

wizgod

    I'm what you guys call a User

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

Posted 27 March 2015 - 09:28 AM

Hi Tarek!

 

These are some of the actions I set which works great when I navigate STV's autogenerated views.

//////////////////////////////////////////////////////////////
// objective.points property
//////////////////////////////////////////////////////////////
var pointsDef = objectiveDef.propertyDefinitionWithName("points")

//////////////////////////////////////////////////////////////
// points.detailModel
//////////////////////////////////////////////////////////////
pointsDef.cellActions.detailModelConfigured = {
    (cell, indexPath, detailModel) in
    
    detailModel.modelActions.didScroll = {
        (tableModel) in
    }
}

pointsDef.cellActions.detailModelDidPresent = {
    (cell, indexPath, detailModel) in
}

pointsDef.cellActions.detailModelWillDismiss = {
    (cell, indexPath, detailModel) in
}

pointsDef.cellActions.detailModelConfigured = {
    (cell, indexPath, detailModel) in
    
    detailModel.modelActions.didFetchItemsFromStore = {
        (itemsModel, items) in
    }
    
    detailModel.sectionActions.cellForRowAtIndexPath = {
        (itemsSection, indexPath) in
    }
    
    detailModel.sectionActions.detailModelWillPresent = {
        (section, detailModel, indexPath) in
    }
    
    detailModel.sectionActions.detailModelDidPresent = {
        (section, detailModel, indexPath) in
    }
    
    detailModel.sectionActions.detailModelWillDismiss = {
        (section, detailModel, indexPath) in
    }
}

 

When I manually push out a datadef, I will have to duplicate what I need; I.E. setting the header, custom cell, view controller title, sectionHeaderTitleForItem, etc.

 

The code where I push the view controller (from the other thread), which is probably familiar to everyone by now :lol: :

 

tableViewModel.cellActions.didSelect = {
(cell, indexPath) in

// If we're in edit mode or adding a new child, show the detail view.
if cell.ownerTableViewModel.tableView.editing || cell.ownerTableViewModel.activeCell == nil || cell.ownerTableViewModel.activeCell.boundObject == nil
{
	(cell.ownerSection as SCArrayOfObjectsSection).dispatchEventSelectRowAtIndexPath(indexPath)
	
	return
}

// If not, go to the list of objectives for the child.
var viewController = SCTableViewController(style: UITableViewStyle.Grouped)
viewController.navigationBarType = SCNavigationBarType.AddEditRight
viewController.title = "Objectives"

var section = SCArrayOfObjectsSection(headerTitle: "Objectives", entityDefinition:objectiveDef, filterPredicate: NSPredicate(format: "child == %@", cell.boundObject))

section.sectionActions.cellForRowAtIndexPath = {
	(itemsSection, indexPath) in
	
	let customCell = SCCustomCell(text: nil, objectBindingsString: nil, nibName: "Objective")

	return customCell
}

// Set the tableHeaderView.
viewController.actions.willAppear = {
	(viewController: SCTableViewController!) in
	
	let photoCell = SCCustomCell(text: nil, objectBindingsString: nil, nibName: "Photo")
	photoCell.boundObject = cell.boundObject

	viewController.tableViewModel.tableView.tableHeaderView = photoCell.contentView
}

viewController.tableViewModel.addSection(section)

cell.ownerTableViewModel.viewController.navigationController!.pushViewController(viewController, animated:true)
}

 

So I have to duplicate all the code that I had in the propertyDef detail actions into the tableViewModel of the pushed view controller.

 

I was thinking of a constructor where you gave the propertyDef and arrayOfObjects and STV could run with it that way.

 

let objectives = cell.boundObject.valueForKey("objectives")

var section = SCArrayOfObjectsSection(headerTitle: "Objectives", propertyDefinition:objectivesPropertyDef, boundObject: objectives))

 

Thanks!

 

Wg


Edited by wizgod, 27 March 2015 - 09:46 AM.

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 30 March 2015 - 03:55 PM

Hi Wg,

 

Please note that the main job of data definitions is to generate the UI. when you manually generate UI, the data definitions are not in action anymore (except data definitions of the detail views of the view you manually generated).  When the data definitions are not used, you can define all of their actions directly in the code where you generate the UI, just as you did in your posted code sample. There is no relationship whatsoever between the data definitions and your manually generated UI anymore.

 

Having said that, you don't actually have to have duplicate code. You can simply define an action in a variable, then reuse this variable in multiple places. For instance:

 

// define the block here once
let cellForRowAction : SCCellForRowAtIndexPathAction_Block =
        {
            (itemsSection, indexPath) in
            
            let customCell = SCCustomCell(text: nil, objectBindingsString: nil, nibName: "Objective")
            
            return customCell
        }
        
// then use as many times as you wish
section.sectionActions.cellForRowAtIndexPath = cellForRowAction
        
//etc

  • Dave Guerin, ozie and wizgod like this

#5 wizgod

wizgod

    I'm what you guys call a User

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

Posted 30 March 2015 - 07:01 PM

I cannot express the feeling I am feeling at this moment knowing I am able to do that. It's like drinking from the ultimate Pure Source (anyone get that? :lol: )

 

Thanks Tarek!


Wg


  • Dave Guerin likes this

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 30 March 2015 - 07:12 PM

hahahaha, you're most welcome! :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users