UITableView wrong section titles










0















I have been stuck on this error for quite some time now. I have a UITabBar with 2 tabs. The first one contains a UITableViewController with meals on different dates of the week. The second tab contains a UIViewController with a login screen.



The UITableViewController is called 'EettafelView'. It gets it's meals (using Alamofire) from an online source and presents them in the application. They are cached in CoreData and retrieved using a NSFetchedResultsController to present them. For this i'm using the default UITableViewDelegates (numberOfRowsInSection, numberOfSections etc) - If they are relevant i'll post them in an edit.



When the tableview loads and i have set the fetchController and have performed a fetch i pretty-print its objects to test what it holds and if the sort-descriptors have done their job. This leads to the following:



Hollandse stoof met bokbier - Optional("maandag, 20 feb.")
Gehaktballetjes
Quorn gehakt
Stamppot van verse spinazie - Optional("dinsdag, 21 feb.")
Rookworst
Kaasspies
Indiase Curry - Optional("woensdag, 22 feb.")
Kip
Bloemkool
Pasta Mexicane - Optional("donderdag, 23 feb.")
Gehakt
Tofu en Bruine Bonen
Boeuf des Gardiens - Optional("vrijdag, 24 feb.")
Rundvlees
Kastanjechampignons


With pretty-print code:



if let objects = fetchController?.fetchedObjects as? [Gerecht] 
for object in objects
print("(object.basis ?? "") - (object.dateString)")
print("t(object.vlees ?? "")")
print("t(object.vega ?? "")")




This is exactly how it is supposed to be. Thus the FetchController holds the right objects and has them sorted correctly. The view however looks likes this:



EettafelView



The section titles are wrong. The code to retrieve the section titles is as follows:



override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
if let sections = fetchController?.sections, sections.count > 0
return sections[section].name
else
return nil




Which is I think as generic as it can be. What can be the problem of it retrieving the wrong section titles?



EDIT: - CellForRow Method



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
let cell = tableView.dequeueReusableCell(withIdentifier: "Eettafel") as? Eettafel_Cell
let gerecht = fetchController?.object(at: indexPath) as? Gerecht
if let gerecht = gerecht
cell?.gerecht = gerecht


return cell!



EDIT - Gerecht in cellForRow



printing the description of the NSManagedObject (breakpoint at if-let gerecht) gives:



Printing description of gerecht.some:
<Almanapp.Gerecht: 0x1740b77c0> (entity: Gerecht; id: 0xd0000000000c0000 <x-coredata://A6B5411D-DF77-43DE-8084-86C76C42F68A/Gerecht/p3> ; data:
basis = "Hollandse stoof met bokbier";
date = "2017-02-20 00:23:07 +0000";
dateString = "maandag, 20 feb.";
status = nil;
vega = "Quorn gehakt";
vlees = Gehaktballetjes;
)


Which is correct.










share|improve this question
























  • Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

    – Emptyless
    Feb 20 '17 at 0:54











  • Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

    – Juan Curti
    Feb 20 '17 at 1:19











  • what are you using for your sectionNameKeyPath in your fetchedResultsController?

    – Jon Rose
    Feb 20 '17 at 7:05











  • @JuanCurti Didn't make a difference. Still the same as in the screenshot.

    – Emptyless
    Feb 20 '17 at 12:47











  • @JonRose I use the sectionNameKeyPath: "dateString"

    – Emptyless
    Feb 20 '17 at 12:47















0















I have been stuck on this error for quite some time now. I have a UITabBar with 2 tabs. The first one contains a UITableViewController with meals on different dates of the week. The second tab contains a UIViewController with a login screen.



The UITableViewController is called 'EettafelView'. It gets it's meals (using Alamofire) from an online source and presents them in the application. They are cached in CoreData and retrieved using a NSFetchedResultsController to present them. For this i'm using the default UITableViewDelegates (numberOfRowsInSection, numberOfSections etc) - If they are relevant i'll post them in an edit.



When the tableview loads and i have set the fetchController and have performed a fetch i pretty-print its objects to test what it holds and if the sort-descriptors have done their job. This leads to the following:



Hollandse stoof met bokbier - Optional("maandag, 20 feb.")
Gehaktballetjes
Quorn gehakt
Stamppot van verse spinazie - Optional("dinsdag, 21 feb.")
Rookworst
Kaasspies
Indiase Curry - Optional("woensdag, 22 feb.")
Kip
Bloemkool
Pasta Mexicane - Optional("donderdag, 23 feb.")
Gehakt
Tofu en Bruine Bonen
Boeuf des Gardiens - Optional("vrijdag, 24 feb.")
Rundvlees
Kastanjechampignons


With pretty-print code:



if let objects = fetchController?.fetchedObjects as? [Gerecht] 
for object in objects
print("(object.basis ?? "") - (object.dateString)")
print("t(object.vlees ?? "")")
print("t(object.vega ?? "")")




This is exactly how it is supposed to be. Thus the FetchController holds the right objects and has them sorted correctly. The view however looks likes this:



EettafelView



The section titles are wrong. The code to retrieve the section titles is as follows:



override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
if let sections = fetchController?.sections, sections.count > 0
return sections[section].name
else
return nil




Which is I think as generic as it can be. What can be the problem of it retrieving the wrong section titles?



EDIT: - CellForRow Method



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
let cell = tableView.dequeueReusableCell(withIdentifier: "Eettafel") as? Eettafel_Cell
let gerecht = fetchController?.object(at: indexPath) as? Gerecht
if let gerecht = gerecht
cell?.gerecht = gerecht


return cell!



EDIT - Gerecht in cellForRow



printing the description of the NSManagedObject (breakpoint at if-let gerecht) gives:



Printing description of gerecht.some:
<Almanapp.Gerecht: 0x1740b77c0> (entity: Gerecht; id: 0xd0000000000c0000 <x-coredata://A6B5411D-DF77-43DE-8084-86C76C42F68A/Gerecht/p3> ; data:
basis = "Hollandse stoof met bokbier";
date = "2017-02-20 00:23:07 +0000";
dateString = "maandag, 20 feb.";
status = nil;
vega = "Quorn gehakt";
vlees = Gehaktballetjes;
)


Which is correct.










share|improve this question
























  • Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

    – Emptyless
    Feb 20 '17 at 0:54











  • Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

    – Juan Curti
    Feb 20 '17 at 1:19











  • what are you using for your sectionNameKeyPath in your fetchedResultsController?

    – Jon Rose
    Feb 20 '17 at 7:05











  • @JuanCurti Didn't make a difference. Still the same as in the screenshot.

    – Emptyless
    Feb 20 '17 at 12:47











  • @JonRose I use the sectionNameKeyPath: "dateString"

    – Emptyless
    Feb 20 '17 at 12:47













0












0








0








I have been stuck on this error for quite some time now. I have a UITabBar with 2 tabs. The first one contains a UITableViewController with meals on different dates of the week. The second tab contains a UIViewController with a login screen.



The UITableViewController is called 'EettafelView'. It gets it's meals (using Alamofire) from an online source and presents them in the application. They are cached in CoreData and retrieved using a NSFetchedResultsController to present them. For this i'm using the default UITableViewDelegates (numberOfRowsInSection, numberOfSections etc) - If they are relevant i'll post them in an edit.



When the tableview loads and i have set the fetchController and have performed a fetch i pretty-print its objects to test what it holds and if the sort-descriptors have done their job. This leads to the following:



Hollandse stoof met bokbier - Optional("maandag, 20 feb.")
Gehaktballetjes
Quorn gehakt
Stamppot van verse spinazie - Optional("dinsdag, 21 feb.")
Rookworst
Kaasspies
Indiase Curry - Optional("woensdag, 22 feb.")
Kip
Bloemkool
Pasta Mexicane - Optional("donderdag, 23 feb.")
Gehakt
Tofu en Bruine Bonen
Boeuf des Gardiens - Optional("vrijdag, 24 feb.")
Rundvlees
Kastanjechampignons


With pretty-print code:



if let objects = fetchController?.fetchedObjects as? [Gerecht] 
for object in objects
print("(object.basis ?? "") - (object.dateString)")
print("t(object.vlees ?? "")")
print("t(object.vega ?? "")")




This is exactly how it is supposed to be. Thus the FetchController holds the right objects and has them sorted correctly. The view however looks likes this:



EettafelView



The section titles are wrong. The code to retrieve the section titles is as follows:



override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
if let sections = fetchController?.sections, sections.count > 0
return sections[section].name
else
return nil




Which is I think as generic as it can be. What can be the problem of it retrieving the wrong section titles?



EDIT: - CellForRow Method



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
let cell = tableView.dequeueReusableCell(withIdentifier: "Eettafel") as? Eettafel_Cell
let gerecht = fetchController?.object(at: indexPath) as? Gerecht
if let gerecht = gerecht
cell?.gerecht = gerecht


return cell!



EDIT - Gerecht in cellForRow



printing the description of the NSManagedObject (breakpoint at if-let gerecht) gives:



Printing description of gerecht.some:
<Almanapp.Gerecht: 0x1740b77c0> (entity: Gerecht; id: 0xd0000000000c0000 <x-coredata://A6B5411D-DF77-43DE-8084-86C76C42F68A/Gerecht/p3> ; data:
basis = "Hollandse stoof met bokbier";
date = "2017-02-20 00:23:07 +0000";
dateString = "maandag, 20 feb.";
status = nil;
vega = "Quorn gehakt";
vlees = Gehaktballetjes;
)


Which is correct.










share|improve this question
















I have been stuck on this error for quite some time now. I have a UITabBar with 2 tabs. The first one contains a UITableViewController with meals on different dates of the week. The second tab contains a UIViewController with a login screen.



The UITableViewController is called 'EettafelView'. It gets it's meals (using Alamofire) from an online source and presents them in the application. They are cached in CoreData and retrieved using a NSFetchedResultsController to present them. For this i'm using the default UITableViewDelegates (numberOfRowsInSection, numberOfSections etc) - If they are relevant i'll post them in an edit.



When the tableview loads and i have set the fetchController and have performed a fetch i pretty-print its objects to test what it holds and if the sort-descriptors have done their job. This leads to the following:



Hollandse stoof met bokbier - Optional("maandag, 20 feb.")
Gehaktballetjes
Quorn gehakt
Stamppot van verse spinazie - Optional("dinsdag, 21 feb.")
Rookworst
Kaasspies
Indiase Curry - Optional("woensdag, 22 feb.")
Kip
Bloemkool
Pasta Mexicane - Optional("donderdag, 23 feb.")
Gehakt
Tofu en Bruine Bonen
Boeuf des Gardiens - Optional("vrijdag, 24 feb.")
Rundvlees
Kastanjechampignons


With pretty-print code:



if let objects = fetchController?.fetchedObjects as? [Gerecht] 
for object in objects
print("(object.basis ?? "") - (object.dateString)")
print("t(object.vlees ?? "")")
print("t(object.vega ?? "")")




This is exactly how it is supposed to be. Thus the FetchController holds the right objects and has them sorted correctly. The view however looks likes this:



EettafelView



The section titles are wrong. The code to retrieve the section titles is as follows:



override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
if let sections = fetchController?.sections, sections.count > 0
return sections[section].name
else
return nil




Which is I think as generic as it can be. What can be the problem of it retrieving the wrong section titles?



EDIT: - CellForRow Method



override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
let cell = tableView.dequeueReusableCell(withIdentifier: "Eettafel") as? Eettafel_Cell
let gerecht = fetchController?.object(at: indexPath) as? Gerecht
if let gerecht = gerecht
cell?.gerecht = gerecht


return cell!



EDIT - Gerecht in cellForRow



printing the description of the NSManagedObject (breakpoint at if-let gerecht) gives:



Printing description of gerecht.some:
<Almanapp.Gerecht: 0x1740b77c0> (entity: Gerecht; id: 0xd0000000000c0000 <x-coredata://A6B5411D-DF77-43DE-8084-86C76C42F68A/Gerecht/p3> ; data:
basis = "Hollandse stoof met bokbier";
date = "2017-02-20 00:23:07 +0000";
dateString = "maandag, 20 feb.";
status = nil;
vega = "Quorn gehakt";
vlees = Gehaktballetjes;
)


Which is correct.







ios uitableview core-data nsfetchedresultscontroller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 20 '17 at 12:53







Emptyless

















asked Feb 20 '17 at 0:24









EmptylessEmptyless

1,9131025




1,9131025












  • Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

    – Emptyless
    Feb 20 '17 at 0:54











  • Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

    – Juan Curti
    Feb 20 '17 at 1:19











  • what are you using for your sectionNameKeyPath in your fetchedResultsController?

    – Jon Rose
    Feb 20 '17 at 7:05











  • @JuanCurti Didn't make a difference. Still the same as in the screenshot.

    – Emptyless
    Feb 20 '17 at 12:47











  • @JonRose I use the sectionNameKeyPath: "dateString"

    – Emptyless
    Feb 20 '17 at 12:47

















  • Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

    – Emptyless
    Feb 20 '17 at 0:54











  • Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

    – Juan Curti
    Feb 20 '17 at 1:19











  • what are you using for your sectionNameKeyPath in your fetchedResultsController?

    – Jon Rose
    Feb 20 '17 at 7:05











  • @JuanCurti Didn't make a difference. Still the same as in the screenshot.

    – Emptyless
    Feb 20 '17 at 12:47











  • @JonRose I use the sectionNameKeyPath: "dateString"

    – Emptyless
    Feb 20 '17 at 12:47
















Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

– Emptyless
Feb 20 '17 at 0:54





Hollandse Stoof met bokbier should be on a monday (maandag) (as per console output) but in the screenshot is on a tuesday (dinsdag)

– Emptyless
Feb 20 '17 at 0:54













Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

– Juan Curti
Feb 20 '17 at 1:19





Please, change your titleForHeaderInSection for: return fetchController?.sections[section].name And tell me what do you get now

– Juan Curti
Feb 20 '17 at 1:19













what are you using for your sectionNameKeyPath in your fetchedResultsController?

– Jon Rose
Feb 20 '17 at 7:05





what are you using for your sectionNameKeyPath in your fetchedResultsController?

– Jon Rose
Feb 20 '17 at 7:05













@JuanCurti Didn't make a difference. Still the same as in the screenshot.

– Emptyless
Feb 20 '17 at 12:47





@JuanCurti Didn't make a difference. Still the same as in the screenshot.

– Emptyless
Feb 20 '17 at 12:47













@JonRose I use the sectionNameKeyPath: "dateString"

– Emptyless
Feb 20 '17 at 12:47





@JonRose I use the sectionNameKeyPath: "dateString"

– Emptyless
Feb 20 '17 at 12:47












2 Answers
2






active

oldest

votes


















2














Try replacing your titleForHeaderInSection function for this.



override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht
return gerecht.dateString
else
return nil




I think the problem is you were using:



if let sections = fetchController?.sections, sections.count > 0 {
return sections[section].name


Check that and tell me please






share|improve this answer

























  • Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

    – Emptyless
    Feb 20 '17 at 13:03











  • Its ok, I will update my answer. So, it works?

    – Juan Curti
    Feb 20 '17 at 13:04











  • Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

    – Emptyless
    Feb 20 '17 at 13:05











  • @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

    – Juan Curti
    Feb 20 '17 at 13:06











  • That's wrong solution: secitons contains wrong cells!

    – Daniel Smith
    Nov 12 '18 at 7:58



















4














You need to add sort descriptor by sectionNameKeyPath for your fetchRequest as FIRST item in array of sort descriptors:



 let request: NSFetchRequest<YourMO> = YourMO.fetchRequest()
let dateSorting = NSSortDescriptor(key: "date", ascending: true)
let sectionSorting = NSSortDescriptor(key: "sectionIdentifier", ascending: true)
request.sortDescriptors = [sectionSorting, dateSorting]
frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "sectionIdentifier", cacheName: nil)





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42334636%2fuitableview-wrong-section-titles%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Try replacing your titleForHeaderInSection function for this.



    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht
    return gerecht.dateString
    else
    return nil




    I think the problem is you were using:



    if let sections = fetchController?.sections, sections.count > 0 {
    return sections[section].name


    Check that and tell me please






    share|improve this answer

























    • Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

      – Emptyless
      Feb 20 '17 at 13:03











    • Its ok, I will update my answer. So, it works?

      – Juan Curti
      Feb 20 '17 at 13:04











    • Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

      – Emptyless
      Feb 20 '17 at 13:05











    • @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

      – Juan Curti
      Feb 20 '17 at 13:06











    • That's wrong solution: secitons contains wrong cells!

      – Daniel Smith
      Nov 12 '18 at 7:58
















    2














    Try replacing your titleForHeaderInSection function for this.



    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht
    return gerecht.dateString
    else
    return nil




    I think the problem is you were using:



    if let sections = fetchController?.sections, sections.count > 0 {
    return sections[section].name


    Check that and tell me please






    share|improve this answer

























    • Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

      – Emptyless
      Feb 20 '17 at 13:03











    • Its ok, I will update my answer. So, it works?

      – Juan Curti
      Feb 20 '17 at 13:04











    • Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

      – Emptyless
      Feb 20 '17 at 13:05











    • @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

      – Juan Curti
      Feb 20 '17 at 13:06











    • That's wrong solution: secitons contains wrong cells!

      – Daniel Smith
      Nov 12 '18 at 7:58














    2












    2








    2







    Try replacing your titleForHeaderInSection function for this.



    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht
    return gerecht.dateString
    else
    return nil




    I think the problem is you were using:



    if let sections = fetchController?.sections, sections.count > 0 {
    return sections[section].name


    Check that and tell me please






    share|improve this answer















    Try replacing your titleForHeaderInSection function for this.



    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht
    return gerecht.dateString
    else
    return nil




    I think the problem is you were using:



    if let sections = fetchController?.sections, sections.count > 0 {
    return sections[section].name


    Check that and tell me please







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 20 '17 at 13:04

























    answered Feb 20 '17 at 12:59









    Juan CurtiJuan Curti

    1,9351230




    1,9351230












    • Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

      – Emptyless
      Feb 20 '17 at 13:03











    • Its ok, I will update my answer. So, it works?

      – Juan Curti
      Feb 20 '17 at 13:04











    • Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

      – Emptyless
      Feb 20 '17 at 13:05











    • @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

      – Juan Curti
      Feb 20 '17 at 13:06











    • That's wrong solution: secitons contains wrong cells!

      – Daniel Smith
      Nov 12 '18 at 7:58


















    • Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

      – Emptyless
      Feb 20 '17 at 13:03











    • Its ok, I will update my answer. So, it works?

      – Juan Curti
      Feb 20 '17 at 13:04











    • Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

      – Emptyless
      Feb 20 '17 at 13:05











    • @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

      – Juan Curti
      Feb 20 '17 at 13:06











    • That's wrong solution: secitons contains wrong cells!

      – Daniel Smith
      Nov 12 '18 at 7:58

















    Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

    – Emptyless
    Feb 20 '17 at 13:03





    Changed to: if let gerecht = fetchController?.object(at: IndexPath(row: 0, section: section)) as? Gerecht return gerecht.dateString else return nil Else it wouldn't compile, but that works

    – Emptyless
    Feb 20 '17 at 13:03













    Its ok, I will update my answer. So, it works?

    – Juan Curti
    Feb 20 '17 at 13:04





    Its ok, I will update my answer. So, it works?

    – Juan Curti
    Feb 20 '17 at 13:04













    Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

    – Emptyless
    Feb 20 '17 at 13:05





    Yes it works, ill mark it as an answer. But it is still strange how the fetchController sections aren't ordered then. Since it holds the right objects in the right order but somehow the sections aren't ordered the same.

    – Emptyless
    Feb 20 '17 at 13:05













    @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

    – Juan Curti
    Feb 20 '17 at 13:06





    @Emptyless That's true, I would check how the data is fetched and parsed into a Gerecht object to see if there's any mistake there.

    – Juan Curti
    Feb 20 '17 at 13:06













    That's wrong solution: secitons contains wrong cells!

    – Daniel Smith
    Nov 12 '18 at 7:58






    That's wrong solution: secitons contains wrong cells!

    – Daniel Smith
    Nov 12 '18 at 7:58














    4














    You need to add sort descriptor by sectionNameKeyPath for your fetchRequest as FIRST item in array of sort descriptors:



     let request: NSFetchRequest<YourMO> = YourMO.fetchRequest()
    let dateSorting = NSSortDescriptor(key: "date", ascending: true)
    let sectionSorting = NSSortDescriptor(key: "sectionIdentifier", ascending: true)
    request.sortDescriptors = [sectionSorting, dateSorting]
    frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "sectionIdentifier", cacheName: nil)





    share|improve this answer





























      4














      You need to add sort descriptor by sectionNameKeyPath for your fetchRequest as FIRST item in array of sort descriptors:



       let request: NSFetchRequest<YourMO> = YourMO.fetchRequest()
      let dateSorting = NSSortDescriptor(key: "date", ascending: true)
      let sectionSorting = NSSortDescriptor(key: "sectionIdentifier", ascending: true)
      request.sortDescriptors = [sectionSorting, dateSorting]
      frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "sectionIdentifier", cacheName: nil)





      share|improve this answer



























        4












        4








        4







        You need to add sort descriptor by sectionNameKeyPath for your fetchRequest as FIRST item in array of sort descriptors:



         let request: NSFetchRequest<YourMO> = YourMO.fetchRequest()
        let dateSorting = NSSortDescriptor(key: "date", ascending: true)
        let sectionSorting = NSSortDescriptor(key: "sectionIdentifier", ascending: true)
        request.sortDescriptors = [sectionSorting, dateSorting]
        frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "sectionIdentifier", cacheName: nil)





        share|improve this answer















        You need to add sort descriptor by sectionNameKeyPath for your fetchRequest as FIRST item in array of sort descriptors:



         let request: NSFetchRequest<YourMO> = YourMO.fetchRequest()
        let dateSorting = NSSortDescriptor(key: "date", ascending: true)
        let sectionSorting = NSSortDescriptor(key: "sectionIdentifier", ascending: true)
        request.sortDescriptors = [sectionSorting, dateSorting]
        frc = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: "sectionIdentifier", cacheName: nil)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 '18 at 8:02

























        answered Nov 12 '18 at 7:55









        Daniel SmithDaniel Smith

        16618




        16618



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42334636%2fuitableview-wrong-section-titles%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo