问题描述
我正在使用Xcode 4.3.2& iOS 5.1模拟器,在我的项目中,我使用两个视图控制器:testingViewController和detailView.我想在testingViewController中选择tableViewCell后为detailView中的NSString设置值.
I'm using Xcode 4.3.2 & iOS 5.1 simulator, and in my project I am using two View Controllers: testingViewController, and detailView. I want to set values for an NSString in detailView once I didSelect tableViewCell in testingViewController.
为此,我使用了以下代码:
For that i used following code:
我在控制台中同时获得wordName
和wordMeaning
的空值.
I get null values for both wordName
and wordMeaning
in the console.
任何人都有解决方案吗?在此先感谢!
Anyone have a solution? Thanks in Advance!
推荐答案
如果您在testingViewController
和detailView
之间使用情节提要,请在testingViewController
的prepareForSegue:
方法中更改行
If you have a storyboard segue between testingViewController
and detailView
, in your testingViewController
's prepareForSegue:
method you should change line
detailView *dVw = [[detailView alloc] init];
到
detailView *dVw = (detailView *)segue.destinationViewController;
此外,我建议您在detailView.h
文件中更改
Also, I recommend you to change in your detailView.h
file the
@property (nonatomic, assign) NSString *YOUR_STRING;
到
@property (nonatomic, copy) NSString *YOUR_STRING;
这篇关于如何从一个viewcontroller在另一个视图控制器中为NSString设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!