How to send an NSString to another view controller

后端 未结 4 1897
时光说笑
时光说笑 2020-12-22 11:20

I have an IBAction that when triggered calls another method in a different view controller ( APICallsViewController). I\'m looking to also send that method an NSString (m

4条回答
  •  情话喂你
    2020-12-22 12:01

    do this code in APICallsViewController.h

    @interface APICallsViewController : UIViewController{
       NSString *strMessage;
    
    }
    @property(nonatomic,retain) NSString *strMessage;
    
    @end
    

    APICallsViewController.m

     @synthesize strMessage;
    
    - (void)viewDidLoad {
    Nslog(@"%@",strMessage);
    

    }


    -(IBAction) someMethod{
    
        APICallsViewController *apiViewController = [[APICallsViewController alloc] init];
        [self.navigationController pushViewController:apiViewController animated:YES]; 
    
        NSString *message = [NSString stringWithFormat:@"Check out %@", nameLb.text];
        apiViewController.strMessage=message;
        [apiViewController apiGraphUserCheckins];
    
        [apiViewController release];
    
    }
    

提交回复
热议问题