UA-17470720-3

Jump to content


Photo
- - - - -

Grouping an SCArrayOfObjectsSection


  • Please log in to reply
14 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 06 March 2015 - 01:17 PM

Greetings Programs!

 

In my core data app, I have a property which is an Array Of Objects in IB. I want to group it by the bound object's date property but cannot seem to do so.

 

The modelActions.sectionHeaderTitleForItem isn't going to work but I tried it anyways :-)

 

let dataDef = self.dataDefinitionWithIBName("Driver")
var pointsDef = dataDef.propertyDefinitionWithName("points")
pointsDef.cellActions.detailModelConfigured = {
    (cell, indexPath, detailModel) in
    
    // This is for an SCArrayOfItemsModel but I thought I'd try :-)
    detailModel.modelActions.sectionHeaderTitleForItem = {
        (itemsModel, item, itemIndex)->String in
        
        return item.valueForKey("receivedDate") as String
    }
    
    detailModel.sectionActions.cellForRowAtIndexPath = {
        (itemsSection, indexPath) in
        
        let customCell = SCCustomCell(text: nil, objectBindingsString: nil, nibName: "Points")

        customCell.cellActions.willConfigure = {
            (cell, indexPath) in
            
            if let pointsLabel = cell.viewWithTag(2) as? UILabel
            {
                let points = cell.boundObject.valueForKey("numberOfPoints") as Int
                if points < 0
                {
                    pointsLabel.backgroundColor = UIColor.redColor()
                }
            }
        }
        
        return customCell
    }
}

 

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 09 March 2015 - 06:27 AM

Hi Wg,

 

You must tell STV to use an SCArrayOfObjectsModel instead of its default SCArrayOfObjectsSection. You do that via cellActions.detailTableViewModel:

 

myObjectsCell.cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)
    {
        SCArrayOfObjectsModel *detailObjectsModel = [[SCArrayOfObjectsModel alloc] init];  // no need to specify table view here
        detailObjectsModel.modelActions.sectionHeaderTitleForItem = ...
        
        return detailObjectsModel;
    };

 

Hope this helps.


Edited by Tarek, 09 March 2015 - 12:54 PM.
Fixed a typo.


#3 wizgod

wizgod

    I'm what you guys call a User

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

Posted 09 March 2015 - 08:38 AM

Thanks Tarek!

 

I implemented the following but now, nothing shows up in the detail view when I go to add/edit a record.

 

let dataDef = dataDefinitionWithIBName("Person")
// The "points" property is defined as the Array of Objects in IB.
var pointsDef = dataDef.propertyDefinitionWithName("points")
pointsDef.cellActions.detailModelConfigured = {
    (cell, indexPath, detailModel) in
    
    detailModel.sectionActions.detailTableViewModelForRowAtIndexPath = {
        (section, indexPath)->SCTableViewModel in
        
        var detailObjectsModel = SCArrayOfObjectsModel()
        detailObjectsModel.modelActions.sectionHeaderTitleForItem = {
            (itemsModel, item, itemIndex)->String in
            
            return item.valueForKey("receivedDate") as String
        }

        return detailObjectsModel
    }
}

 

Wg


Edited by wizgod, 09 March 2015 - 08:39 AM.

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


#4 wizgod

wizgod

    I'm what you guys call a User

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

Posted 09 March 2015 - 11:52 AM

Ok, so I believe I was using the wrong action since I was already assigning it to the array of objects cell (pointsDef) and changed it to this:

 

let dataDef = dataDefinitionWithIBName("Person")
// The "points" property is defined as the Array of Objects in IB.
var pointsDef = dataDef.propertyDefinitionWithName("points")
pointsDef.cellActions.detailTableViewModel = {
    (cell, indexPath)->SCTableViewModel in

    var detailObjectsModel = SCArrayOfObjectsModel()
    detailObjectsModel.modelActions.sectionHeaderTitleForItem = {
        (itemsModel, item, itemIndex)->String in
        
        return item.valueForKey("receivedDate") as String
    }
    
    return detailObjectsModel
}

 

But I'm still getting a blank object model.

 

Wg


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


#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 09 March 2015 - 01:20 PM

Hi Wg,

 

You're correct, in your case you should use cellActions instead of sectionActions (I just updated my answer too since your case is much more common). I just tested this and there does indeed seem to be a bug with correctly assigning the dataStore for your custom model, which is why it appears empty. Will be fixed in our next release. (We need to issue a release within the next few hours to accommodate the just released Xcode 6.2)



#6 wizgod

wizgod

    I'm what you guys call a User

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

Posted 09 March 2015 - 07:21 PM

Hi Tarek!

 

When I go to the view now, it does show everything grouped as I want it but the app crashes after it displays with no real output as to the reason why. When I remove the code, it works but without the grouping of course.

 

Wg


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 09 March 2015 - 08:00 PM

Hi Wg,

 

Are you able to replicate this on any of our samples (say TasksApp)? We tested there several times and all was working well. Perhaps we have different code?



#8 wizgod

wizgod

    I'm what you guys call a User

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

Posted 10 March 2015 - 09:29 AM

No; I used the Core Data sample app and added a dueDate to the TaskStepEntity and I took the obj-c equivalent of my code, threw it in there and had no problems.

 

SCDataDefinition *taskDef = [self dataDefinitionWithIBName: @"TaskEntity"];
SCPropertyDefinition *taskStepDef = [taskDef propertyDefinitionWithName: @"taskSteps"];
taskStepDef.cellActions.detailTableViewModel = ^SCTableViewModel*(SCTableViewCell *cell, NSIndexPath *indexPath)
{
    SCArrayOfObjectsModel *detailObjectsModel = [[SCArrayOfObjectsModel alloc] init];  // no need to specify table view here
    detailObjectsModel.modelActions.sectionHeaderTitleForItem = ^NSString*(SCArrayOfItemsModel *itemsModel, NSObject *item, NSUInteger itemIndex)
    {
        NSManagedObject *taskStep = (NSManagedObject *)item;
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"MM dd yyyy"];
        
        return [formatter stringFromDate:[taskStep valueForKey:@"dueDate"]];
    };
    
    return detailObjectsModel;
};

 

However, I am receiving these warnings in my code and possibly this is the cause:

 

2015-03-10 10:55:29.519 myApp[2875:630799] -[myApp.Activity compare:]: unrecognized selector sent to instance 0x1702aabc0
2015-03-10 10:55:29.520 myApp[2875:630799] **STV** Warning: Invalid sort key: activity or orderAttribute:(null).

 

I don't set a sort key or orderAttribute anywhere in my code so I don't know why this would be popping up.

 

Thoughts?

 

Wg


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


#9 wizgod

wizgod

    I'm what you guys call a User

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

Posted 10 March 2015 - 12:34 PM

I at least got rid of the warnings:

 

I went throught the model, removed the "myApp." from all the class names, rebuilt and put them back in.

Then I went through and deselected all Integer32 properties who had a "default" set and then reselected them. Some of them were order properties used for the Order Attribute.

 

I have no clue as to why this got rid of the warnings but it still crashes.

 

Wg


Edited by wizgod, 10 March 2015 - 12:35 PM.

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


#10 wizgod

wizgod

    I'm what you guys call a User

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

Posted 10 March 2015 - 01:43 PM

Tarek,

 

In the CoreData sample app with the code above, what I faild to notice was that when you set the "Add New Text" property to something, the Add New Cell does not show up and the "+" is no longer present.

 

Wg


Edited by wizgod, 10 March 2015 - 01:44 PM.

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


#11 wizgod

wizgod

    I'm what you guys call a User

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

Posted 10 March 2015 - 01:59 PM

I stripped down my app and have the grouping working but the above issue with the Add New Text property/cell still exists.

 

Wg


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


#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 16 March 2015 - 07:37 AM

Hi Wg,

 

Since SCArrayOfObjectsModel is a collection of multiple automatically generated sections, it does not support the concept of "addNewItemCell" that SCArrayOfObjectsSection supports (since there isn't one single section to place the cell in when items are grouped). 



#13 wizgod

wizgod

    I'm what you guys call a User

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

Posted 16 March 2015 - 07:52 AM

Makes sense; thanks Tarek!

 

Wg


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


#14 wizgod

wizgod

    I'm what you guys call a User

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

Posted 22 March 2015 - 01:29 AM

However, I am receiving these warnings in my code and possibly this is the cause:

 

2015-03-10 10:55:29.519 myApp[2875:630799] -[myApp.Activity compare:]: unrecognized selector sent to instance 0x1702aabc0
2015-03-10 10:55:29.520 myApp[2875:630799] **STV** Warning: Invalid sort key: activity or orderAttribute:(null).

 

I don't set a sort key or orderAttribute anywhere in my code so I don't know why this would be popping up.

 

Thoughts?

 

Wg

 

These warnings returned in my app and I have discovered why they are occurring. For the Point Entity Definition in IB, I had the Key Property and Title Property set to "activity", an Object Selection of the Activity Entity Definition. When I switched the property names to another property, the warnings were gone.

 

I tried replicating the issue in my other definitions which had an object selection but the issue was specific to the Points Entity Definition and the Activity Entity.

 

At least it's not a mystery anymore :-)


Wg


Edited by wizgod, 22 March 2015 - 01:29 AM.

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


#15 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 23 March 2015 - 08:36 AM

Thanks for the update Wg :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users