助けてください、私の配列'resultArray'にオブジェクトを保持するために何をする必要がありますか?「保持」を使用しましたが、役に立ちませんでした。'doMyAction'でアクセスすると、配列にオブジェクトがあります。次に、try2FlipsideViewControllerに接続する "performSegueWithIdentifier"を実行します。ここで、最初のコントローラーで定義された "setText"メソッドにアクセスしようとすると、配列にオブジェクトがなくなります。
実際、私の目標は、メインコントローラーで決定されたエラーメッセージをフリップコントローラーに表示することです。また、文字列を「homeController.resultDisplay.text=self.myTextField.text;」としてプッシュしようとしました。しかし、それはコンパイルされ、何も起こりません。
どんな助けや提案も歓迎されます、ありがとう。
try2MainViewController.m
#import "try2MainViewController.h"
#import "try2Model.h"
@interface try2MainViewController ()
@property (nonatomic,strong) try2Model * brain;
@property (retain, nonatomic) NSMutableArray * resultArray;
@end
@implementation try2MainViewController
@synthesize myTextField;
@synthesize brain = _brain;
@synthesize resultArray;
- (IBAction)doMyAction:(id)sender {
resultArray = [self.brain someMethod];
NSString * resultCode = (NSString *)[resultArray objectAtIndex:0];
if ([resultCode isEqualToString:@"1"]) {
NSNumberFormatter * myFormat = [[NSNumberFormatter alloc]init];
[myFormat setPositiveFormat:@"0.##"];
NSNumber * testNo = (NSNumber *)[resultArray objectAtIndex:1];
NSString * anca = [myFormat stringFromNumber:testNo];
self.myTextField.text = [NSString stringWithFormat: @"<< result %@%%",anca];
}
NSString * r = (NSString *)[resultArray objectAtIndex:1];//*&* test
[self performSegueWithIdentifier: @"showAlternate"
sender: self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
try2FlipsideViewController * homeController = (try2FlipsideViewController *)[segue destinationViewController];
homeController.resultDisplay.text = self.myTextField.text;
[[segue destinationViewController] setDelegate:self];
}
}
- (NSString *) setText {
NSString * r = (NSString *)[resultArray objectAtIndex:1];//*&* test
return r;
}
try2FlipsideViewController.m
#import "try2FlipsideViewController.h"
#import "try2MainViewController.h"
@interface try2FlipsideViewController ()
@property (nonatomic,strong) try2MainViewController * getMain;
@end
@implementation try2FlipsideViewController
@synthesize delegate = _delegate;
@synthesize resultDisplay = _resultDisplay;
@synthesize getMain = _getMain;
-(try2MainViewController *)getMain
{
if (!_getMain) {
_getMain = [[try2MainViewController alloc] init];
}
return _getMain;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
r = [self.getMain setText];
self.resultDisplay.text = r
}