开发者

Managing dates in Section Headers with Core Data

开发者 https://www.devze.com 2023-03-13 16:25 出处:网络
I have conceptual issue with using core data. My app lists events by title in the main tableview then navigates to a tableview which is unique to the event. Here it\'s supposed to display in the secti

I have conceptual issue with using core data. My app lists events by title in the main tableview then navigates to a tableview which is unique to the event. Here it's supposed to display in the section headers of the tableview an event date, a list of dates that expand a range (requires calculation) or list of unique dates.

I have arranged this in the model with 3 entities. Event & Date have a one to one relationship. Date to Menu have a one 开发者_开发百科to many relationship. Menu contains the data for events that have unique dates, Dates contains events that either have a start date or in some cases when it's a range an end date.

Ok if the above is clear my question is how do I do create a list of section headers unique to an event? Bear in mind that NSFetchedResultsController only provides the ability to return a section name from a managedObject. I think this is what's throwing me.

Do I fetch the data unique to the event then use FRC to create arrays to populate the section headers and live with the table not being managed? Or is there a smarter way?


I don't really understand your model but I think it looks something like this:

Event{
  name:string
  date<-->Date.event
}

Date{
  event<-->Event.date
  menus<-->>Menu.date
}

Menu{
  date<<-->Date.menus
}

If this isn't correct, you might try editing the question with the data model in this format it can be better understood. (if you can't edit, just fold the format into a comment and I will add it. Alternatively, send it me in an email.)

I'm not clear on what data you want in your Event table section titles. Sections are intended to be groupings of managed objects based on some attribute of those objects. The canonical example would be Contact.app's contact list. The contacts are grouped based on alphabetical value of the first letter of the last name.

Once common mistake is to think of a section table as representing hierarchal objects with the section titles representing superior objects and the rows representing inferior e.g. yo have a model to simulate a file system so you have a Directory entity and a File entity. You try to set the section titles to the name of the Directory and the rows to the names of the related File entities. That would not work smoothly and would not really mesh with the interface grammar that the user has learned for section titles. Instead, you should have a hierarchy of tableviews with a table showing all Directory objects and then a second table view showing all the File objects related to the selected `Directory object.

So, if the section titles you want come from any object besides Event you are probably approaching the problem from the wrong angle.

0

精彩评论

暂无评论...
验证码 换一张
取 消