Pass data back to the previous controller

前端 未结 4 1080
无人共我
无人共我 2020-12-04 18:33

I have two controllers in the storyboard, embedded in a NavigationController, and there is a segue to switch between these.

Passing data from the first controller to

4条回答
  •  爱一瞬间的悲伤
    2020-12-04 19:36

    In your second view controller class you create a protocol and delegate. The first view controller will set it self as the delegate in prepareForSegue and implement the protocol methods. The second view controller will then call the methods to pass data back to the first view controller. Here is some code from one of my projects as an example.

    @protocol TableSelectorDelegate 
    
    @optional
    - (void)didMakeSelection:(id)selectionString forType:(NSString *)dataTitle;
    - (void)didAddNewValue:(NSString *)newValue forType:(NSString *)dataTitle;
    
    @end
    
    @interface TableSelectorViewController : UITableViewController  
    
    @property (nonatomic, weak) id delegate;
    
    @end
    

提交回复
热议问题