0

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

MasterViewController.h:

#import <UIKit/UIKit.h>

@interface MasterViewController : UIViewController <UITextFieldDelegate>

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

@end

主视图控制器.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

疾病结果视图控制器.h

#import <UIKit/UIKit.h>

@class MySymptomsBookDataController;

@interface DiseaseResultsViewController : UITableViewController

@property (nonatomic, strong) NSString *symptomSearchString; 

@property (nonatomic, strong) MySymptomsBookDataController *dataController;


@end

顺便说一句,我用 NSString 和 NSMutableString 都试过了,但没有用

然后我使用症状搜索字符串来创建一个数据控制器。

- (void)awakeFromNib
{
    [super awakeFromNib];

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

但是因为字符串是 nil 它会压碎。有小费吗?

4

2 回答 2

0

你有@synthesize 变量吗?在他们中

于 2013-10-12T04:09:14.800 回答
0

不要弄乱目标视图控制器上的插座。相反,将 NSString 属性添加到目标并将其设置为 in -prepareForSegue:,然后在-viewDidAppear目标控制器上使用该值来填充您的 UI。

于 2013-10-11T22:15:36.680 回答