UA-17470720-3

Jump to content


Photo
- - - - -

Sorting and adding to SCArrayOfObjectsModel


  • Please log in to reply
4 replies to this topic

#1 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 09 November 2015 - 12:54 AM

I have added section headers to my master view using the code in the manual:

 

    // Create the new objectsModel
    let objectsModel = SCArrayOfObjectsModel(tableView: self.tableView)
    
    // Implement the sectionHeaderTitleForItem action to return the first character of each task's name
    objectsModel.modelActions.sectionHeaderTitleForItem =
        {
            (itemsModel, item, itemIndex)->String! in
            
            let taskName = item.valueForKey("name") as! String
            
            // Return first charcter of taskName capitalized
            return taskName.substringToIndex(advance(taskName.startIndex, 1)).uppercaseString
        }
    
    // Enable automatic search functionality
    objectsModel.enableSearchController = true
    
    // Override STV's default SCTableViewModel with your new objectsModel
    self.tableViewModel = objectsModel

 

However, now my code to sort the tableland to add new records no longer works. I assume that this sis because i have changed the model to SCArrayOfObjectsModel so how do I sort that or add new records to it?

 

thanks

karl

 



#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 10 November 2015 - 09:45 AM

Hi Karl,

 

Is this the same issue mentioned here? http://sensiblecocoa...ler/#entry12994



#3 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 10 November 2015 - 11:37 AM

Sorry, I was not clear.

When i say it doesn't work, I mean it causes a crash.

Before I added the code for sections headers, the following code worked ok:

 

        
        let myObjectsSection = self.tableViewModel.sectionAtIndex(0) as! SCArrayOfObjectsSection
        myObjectsSection.dataFetchOptions.sort = true

 

But now it causes an exception, because sectionAtIndex(0) is nil.


Edited by Karl1348790294, 10 November 2015 - 11:37 AM.


#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 10 November 2015 - 11:42 AM

Oh I see what you mean now. In an SCArrayOfObjectsModel, all the sections get generated on the fly (much like an SCArrayOfObjectsSection generates its cells), so you should avoid directly accessing them. You should use 'myObjectsModel.dataFetchOptions' instead.



#5 Karl1348790294

Karl1348790294

    Experienced Member

  • STV 5.0 Std
  • PipPipPipPip
  • 90 posts
Reputation: 6
Good

Posted 10 November 2015 - 12:25 PM

OK, that works, thank you

karl






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users