如何将 NSString 发送到另一个视图控制器 [英] How to send an NSString to another view controller

查看:20
本文介绍了如何将 NSString 发送到另一个视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 IBAction,它在触发时调用不同视图控制器 (APICallsViewController) 中的另一个方法.我还希望向该方法发送一个 NSString(消息)

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 (message)

这是我的 IBAction,它推送到 APICallsViewController 以及 NSString 消息.我的问题可能是如何在另一个视图控制器的方法中获取该 NSString 的内容.

here's my IBAction with the push to the APICallsViewController and also the NSString message. My question might be how do I grab the contents of that NSString in the other view controller's method.

感谢您的帮助

-(IBAction) someMethod{
        APICallsViewController *apiViewController = [[APICallsViewController alloc] init];
        [self.navigationController pushViewController:apiViewController animated:YES]; 

        NSString *message = [NSString stringWithFormat:@"Check out %@", nameLb.text];

        [apiViewController apiGraphUserCheckins];

        [apiViewController release];

}

推荐答案

在 APICallsViewController.h 中做这段代码

do this code in APICallsViewController.h

@interface APICallsViewController : UIViewController{
   NSString *strMessage;

}
@property(nonatomic,retain) NSString *strMessage;

@end

APICallsViewController.m

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];

}

这篇关于如何将 NSString 发送到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆