ios - Reorder dynamic UITableView by NSDate -


in app have uitableview fill core date items.

as can see in post, have asked sorting function: https://stackoverflow.com/a/36703648/6012187

func resort() {    coredataitems.sortinplace({sortascending ? $0.rowname < $1.rowname : $0.rowname > $1.rowname})    sortascending = !sortascending    tableview.reloaddata() } 

now question is, how can set dynamically rowname value? example. save the rowname in user defaults.

but $0.defaults.objectforkey("xx") doesn't work without syntax error

next question is:

how can sort row, value nsdate?

you can sort nsarray contains nsdate using code:

// objective-c code nssortdescriptor *datedescriptor = [nssortdescriptor                              sortdescriptorwithkey:@"startdatetime"                                           ascending:yes]; nsarray *sortdescriptors = [nsarray arraywithobject:datedescriptor]; nsarray *sortedeventarray = [nodeeventarray  sortedarrayusingdescriptors:sortdescriptors];  //swift code let datedescriptor :nssortdescriptor = nssortdescriptor(key: "startdatetime", ascending: true) let sortdescriptors: nsarray = [datedescriptor] let sortedeventarray = nodeeventarray.sortedarrayusingdescriptors([datedescriptor]) 

after sorting done, can reload tableview


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -