UA-17470720-3

Jump to content


Photo
- - - - -

Add Button Does Not Work When SCArrayOfObjectsModel is Nil


  • Please log in to reply
6 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 21 April 2015 - 09:29 AM

Greetings Programs!

 

When I push the view controller in the following manner, if the filter for the entityDefinition does not return any results, the Add button has no effect. When I navigate down to the points view when in edit mode, the Add button does work if there are no previous records.

 

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

// If we're in edit mode or adding a new objective, 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 points for the objective.
let objective = cell.boundObject as! Objective

var viewController = SCTableViewController(style: UITableViewStyle.Grouped)
viewController.navigationBarType = SCNavigationBarType.AddRight
viewController.title = objective.objectiveTitle

let tableViewModel = SCArrayOfObjectsModel(tableView: viewController.tableView, entityDefinition:pointDef, filterPredicate: NSPredicate(format: "objective == %@", cell.boundObject))

viewController.tableViewModel = tableViewModel

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

 

Wg

 


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


#2 wizgod

wizgod

    I'm what you guys call a User

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

Posted 22 April 2015 - 08:52 PM

I also found that when I push the view controller, and add a new record (when other records exist), the following happens:

 

tap Done and the record is not added/committed or show up in the tableview.

 

If I'm in edit mode and navigating down via STV, it's fine.

 

EDIT:

 

I solved this particular problem by adding the following action; it didn't work when there were no records unfortunately:

 

tableViewModel.modelActions.didFetchItemsFromStore = {
    (itemsModel, items) in
    
    itemsModel.dataStore.bindStoreToPropertyName("points", forObject: cell.boundObject, withDefinition: objectiveDef)
}

 

Wg


Edited by wizgod, 23 April 2015 - 11:10 AM.

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


#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 April 2015 - 09:08 AM

Hi Wg,

 

Does the newly added objects satisfy your filter condition? Keep in mind that STV tests the newly added objects against your filter and will not display them if they don't satisfy it.



#4 wizgod

wizgod

    I'm what you guys call a User

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

Posted 27 April 2015 - 09:52 AM

Hi Tarek,

 

When I bindStoreToPropertyName I see the new record; when I don't bind, I don't see the new record and if the filter returns no records, I am unable to add a new record.

 

Wg


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


#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 May 2015 - 02:58 PM

Here's where I am right now:

1. When the property "points" (NSSet) is nil, I am unable to add a new record (tapping "+" does nothing)

2. When the property "points" has a record, tapping "+" to add a new record works.

 

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

// If we're in edit mode or adding a new objective, 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 points for the objective.
var viewController = SCTableViewController(style: UITableViewStyle.Grouped)
viewController.navigationBarType = SCNavigationBarType.AddEditRight
viewController.title = objective.objectiveTitle

let tableViewModel = SCArrayOfObjectsModel(tableView: viewController.tableView, entityDefinition:pointDef)

tableViewModel.dataStore.bindStoreToPropertyName("points", forObject: cell.boundObject, withDefinition: objectiveDef)

viewController.tableViewModel = tableViewModel

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

 

Wg


Edited by wizgod, 19 May 2015 - 07:10 PM.

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


#6 wizgod

wizgod

    I'm what you guys call a User

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

Posted 22 May 2015 - 01:39 PM

Finally figured out a workaround.

 

At first I was adding an empty record so the user could at least add a new record (and trying to remove the empty record after the user added one) but that was nasty so I stopped with that.

 

Then I found that ozie had pretty much the same problem here: http://sensiblecocoa...model-problems/ and was experimenting with a placeholder cell. I was actually going to add an "Add Point" button cell at the bottom (because addNewItemCellExistsInNormalMode does not work with SCArrayOfObjectsModel) but thought I'd wait till the "Add" problem got fixed first - not any more ;-).

 

This solved the problem; now that the items list is not empty (has the button cell), the add button (+) works as expected.

tableViewModel.modelActions.didFetchItemsFromStore = {
    (itemsSection, items) in

    var buttonCell = SCTableViewCell(text: "Add Point", textAlignment: NSTextAlignment.Center)
    buttonCell.cellActions.didSelect = {
        (cell, indexPath) in
        
        (cell.ownerSection as! SCArrayOfObjectsSection).dispatchEventAddNewItem()
    }
    
    items.addObject(buttonCell)
}

 

Wg


Edited by wizgod, 22 May 2015 - 01:47 PM.

  • Tarek likes this

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


#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 02 June 2015 - 12:12 PM

Just confirming that this has now been fixed in 4.2.4.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users