Pass back data using [popviewcontroller], and reload data

送分小仙女□ 提交于 2019-12-04 22:02:47

Hacker's approach would work.

Apple's documentation suggests a slightly different technique. Define a simple protocol with a method that view controller C can use to communicate with view controller B.

Then give view controller C a delegate property that conforms to that protocol.

In your prepareForSegue method, set yourself as view controller C's delegate.

Then, in view controller C, when the user changes the date and clicks the button, invoke a delegate method to notify view controller B that the user changed the date value before popping yourself.

I would suggest adding a cancel button as well, so the user can discard their changes. In that case, you just would skip calling the delegate method before popping.

in the interface of your view controller C add a property

@property (nonatomic, strong) NSDate *selectedDate;

before pushing C from B do

[cViewController addObserver:self forKeyPath:@"selectedDate" options:0 context:NULL];

and implement

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    //do some stuff
}

in view controller B.

when selecting a new date do (in view controller V)

self.date = myPicker.date;

so view controller B gets notified when the new date is set

don't forget to remove the observer in implementation of B (e.g. viewWillAppear)...

[cViewController removeObserver: self....];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!