将NSString值传递给目标C中的另一个ViewController [英] Pass NSString value to another ViewController in Objective C

查看:93
本文介绍了将NSString值传递给目标C中的另一个ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将NSString值传递给另一个ViewController.但是我得到的是null而不是值.这是我的代码. FirstViewController.m:

I am trying to pass NSString value to another ViewController. But I get null instead of the value. Here is my code. FirstViewController.m:

NSString cellID = @"66";
    SecondViewController *apiViewController = [[SecondViewController alloc] init];
                 apiViewController.strMessage=cellID;
                 [self.navigationController pushViewController:apiViewController animated:YES];

SecondViewController.h:

SecondViewController.h:

@interface SecondViewController : UIViewController{
    NSString *strMessage;

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

SecondViewController.m:

SecondViewController.m:

@implementation SecondViewController
@synthesize strMessage;
NSLog(@"%@", strMessage);
@end

我确实导入了.我在推送之前分配了变量.但是无论如何它返回空值.我怎样才能做到这一点?任何提示,想法.谢谢.

I did import. I assigned variable before pushing. But it anyway returns null. How can I do this? Any tips, ideas. Thank you.

推荐答案

尝试一下

SecondViewController *apiViewController = [[SecondViewController alloc] init];
 apiViewController.strMessage=cellID;
[self.navigationController pushViewController:apiViewController animated:YES];

然后打印

NSLog(@"%@", self.strMessage);

这篇关于将NSString值传递给目标C中的另一个ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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