ios - How can I reload a UITableView in a VC as soon as the presented modal vc is dismissed? -


i working in swift 2 , have master-detail-template. detail view controller contains table view, in elements can added on modal view, presented detail view controller (using core data). tried use delegate integrated detail view controller, tells reload table view's data when modal view dismissed, doesn't reload data until select element in master view of master-detail-template. delegate in newsittingvc:

protocol newsittingvcdelegate {     func savereload() } 

when user wants dismiss modal view, code called:

self.delegate!.savereload() presentingviewcontroller!.dismissviewcontrolleranimated(true, completion: nil) 

which calls in detail view vc:

func savereload() {     sittingtable.reloaddata()     //self.view.setneedsdisplay() } 

it doesn't work way described. know way work. forcing view redraw setneedsdisplay() didn't work.

edit: this xcode looks when set breakpoint. tips how precede information?

read answer describe have sync backing store along uitableview. you've got pretty similar problem.

in callback, you're calling sittingtable.reloaddata(). does? calls these uitableviewdatasource delegate methods numberofsections..., ... along tableview(_:cellforrowatindexpath:). , these methods what? return values based on sitzungen array (count, ...). , know problem - did update sitzungen array? no, didn't.

so, in savereload() method have execute fetch request again (in same way in setupsittingtable) , when sitzungen array updated, (no sooner) call sittingtable.reloaddata(). should fix problem.


another points ...

don't call delegate methods in way ...

self.delegate!.savereload() 

... change ...

self.delegate?.savereload() 

... what's difference? assume delegate optional (?) , when delegate not set (nil), crash. because ! force unwrapping optional , if it's nil, crashes. if replace ! ? this:

  • if self.delegate != nil - savereload() called,
  • if self.delegate == nil - nothing happens , no crash well.

you can learn more in optional chaining chapter, in calling methods through optional chaining.

don't use sittingcell class name. class name, types, ... should start upper case letter (camel case). correct class name sittingcell. first lower case letter used function name, property name, ...

also please, next time, don't use images, it's better copy & paste & format code in question text. it's hard read it, ...


Comments