Using blocks to pass data back to view controller

后端 未结 4 530
没有蜡笔的小新
没有蜡笔的小新 2021-01-06 11:20

I was looking at this question.

One of the answers shows how to use blocks to pass data backwards view the prepareForSegue method. My understanding is t

4条回答
  •  自闭症患者
    2021-01-06 11:50

    sent data backward

    1. declare block in your secondViewController.h file

      @property (nonatomic, copy)void(^myBlock)(NSString *);

    2. call block wherever you need to pass data from .m file of secondViewController

      myBlock(@"this will displayed in firstViewController");

    3.import above .h file in your firstViewController .m file and define your block as

    secondViewController *ref =[[secondViewController alloc ]init];
      
         ref.myBlock =^void(NSString *data)
        {
        self.labelOffirstviewcontroller=data;
        };
    

提交回复
热议问题