iphone - 如何将 NSString 发送到另一个 View Controller

标签 iphone objective-c ios uiviewcontroller nsstring

我有一个 IBAction,它在触发时调用不同 View Controller (APICallsViewController) 中的另一个方法。我还希望向该方法发送 NSString(消息)

这是我的 IBAction 推送到 APICallsViewController 和 NSString 消息。我的问题可能是如何在另一个 View Controller 的方法中获取该 NSString 的内容。

谢谢你的帮助

-(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 中执行此代码

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

}

关于iphone - 如何将 NSString 发送到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10719017/

相关文章:

iphone - 调整 UIView 的大小

iPhone/iPad WebApps 不允许 cookie?

ios - 为什么我没有收到 eBay 的产品价格回复?

iphone - 当 key 未知时获取对象?

ios - 如何在 Storyboard 中将自定义字体设置为 UILabel

ios - 在哪里使用 'GL_EXT_color_buffer_half_float' ?

iphone - 我将如何在首次运行时呈现特定区域的 map View ?

objective-c - 如何使用 Objective C 在 iOS 中实现 GPS 功能?

ios - 根据ISOCountryCode获取货币符号和货币代码

ios - 当我的应用程序从图库返回时,它具有导航栏的标准颜色