Pass value to parent controller when dismiss the controller

前端 未结 3 671
广开言路
广开言路 2021-01-06 07:12

I want to send data to parentviewcontroller but the following code crashes. Give me the solution

Post *vc;
vc.abc =@\"Comment Conttroller\";
[self.parentView         


        
3条回答
  •  天命终不由人
    2021-01-06 08:04

    Take this in .h file in ParentViewController

    NSString *strABC;
    

    Make below function in ParentViewController

    -(void)setString:(NSString *)strEntered{
        strABC=strEntered;
    }
    

    Now In Post view controller do like this:

    ParentViewController *objSecond = 
      [[ParentViewController] initwithNibName:@"parentView.xib" bundle:nil];
    
    [objSecond setString:@"Comment Controller"];
    [self.navigationController pushViewController:objSecond animated:YES];
    [objSecond release];
    

    Now, In secondViewController viewWillAppear method write this.

    -(void)viewWillAppear:(BOOL)animated{
          lblUserInput.text = strABC;
    }
    

    Please check spelling mistakes as I've hand written this. Hope this help.

    If you are not using UINavigationContoller then you can do something like this.

    SecondViewControler *objSecond = 
      [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];
    [objSecond setUserInput:txtUserInput.text];
    [objSecond viewWillAppear:YES];
    [self.view addSubview:objSecond];
    [objSecond release];
    

提交回复
热议问题