Sending data from one ViewController to another.

后端 未结 1 625
逝去的感伤
逝去的感伤 2020-12-07 04:09

I have got two ViewController:

1) ViewController

2) TestAppViewController

In ViewController.h

相关标签:
1条回答
  • 2020-12-07 04:42

    Using delegate:

    In TestAppViewController.h:

       @protocol messageDelegate <NSObject>
        @optional
        -(void)test:(NSString*)str;
        @end
        @interface SecondViewController : NSString
        @property (nonatomic, assign) id <messageDelegate> delegate;
        @end
    

    In TestAppViewController.m:

    -(void)readyToSend
    {
        [self.delegate test:@"Hello world!"];
    
    }
    

    In ViewController.h:

    @interface ViewController : UIViewController<messageDelegate>
    @end
    

    In ViewController.m: in

    - (void)viewDidLoad {
    TestAppViewController * testAppViewController = [[TestAppViewController alloc] init];
    testAppViewController.delegate = self;
    }
    -(void) test:(NSString*)str{
    NSLog(@"%@,str");
    }
    

    Hope it will help!

    0 讨论(0)
提交回复
热议问题