通过segue传递的字符串总是为零

时间:2013-10-11 22:12:04

标签: ios objective-c

我试图从带有segues的文本字段传递一个字符串,但它总是变为nil

MasterViewController.h:

#import <UIKit/UIKit.h>

@interface MasterViewController : UIViewController <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *symptomTextField;

@end

MasterViewController.m

#import "MasterViewController.h"
#import "DiseaseResultsViewController.h"
@interface MasterViewController ()

@end

@implementation MasterViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"My Symptoms Book";

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([[segue identifier] isEqualToString:@"searchFunctionSegue"])
    {
        if ([self.symptomTextField.text length])
        {
            DiseaseResultsViewController *resultsViewController = [segue destinationViewController];
            resultsViewController.symptomSearchString = self.symptomTextField.text;
        }
    }

}


@end

DiseaseResultsViewController.h

#import <UIKit/UIKit.h>

@class MySymptomsBookDataController;

@interface DiseaseResultsViewController : UITableViewController

@property (nonatomic, strong) NSString *symptomSearchString; 

@property (nonatomic, strong) MySymptomsBookDataController *dataController;


@end

btw我用NSString和NSMutableString尝试了这个并且它不起作用

然后我使用symptomSearchString创建一个datacontroller。

- (void)awakeFromNib
{
    [super awakeFromNib];

    self.dataController = [[MySymptomsBookDataController alloc] initDMySymptomsBookDataControllerFromJsonDataWithSymptom:symptomSearchString];
}

但因为字符串是nil,所以它会粉碎。有什么提示吗?

2 个答案:

答案 0 :(得分:0)

请勿弄乱目标视图控制器上的插座。而是将NSString属性添加到目标并在-prepareForSegue:中设置,然后在目标控制器的-viewDidAppear中使用该值来填充UI。

答案 1 :(得分:0)

你有@synthesize变量吗?在.m