배열 'resultArray'에 객체를 유지하려면 어떻게해야합니까? 나는 "보유"를 사용했지만 도움이되지 않았습니다. 배열에는 'doMyAction'에서 액세스 할 때 개체가 있고, 그 다음 try2FlipsideViewController에 연결하는 "performSegueWithIdentifier"를 수행합니다. 여기서 첫 번째 컨트롤러에 정의 된 "setText"메서드에 액세스하려고 시도하고 배열에는 개체가 없습니다.IOS5 배열에 객체를 유지하는 방법
사실 내 목표는 플립 contoler에서 메인 컨트롤러에서 결정된 몇 가지 오류 메시지를 표시하는 것입니다. 또한 문자열을 "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
당신의try2FlipsideViewController
당신이
try2MainViewController
클래스의 새 인스턴스를 브랜드를 만들어
getMain
전화에서
#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
}
당신의'doMyAction'에서 메소드 대신'resultArray = ...'를 사용 해보았습니까?'self.resultArray = ...'를 사용해 보셨습니까? 그렇지 않으면 문제를 일으킬 수있는 설정기를 우회하기 때문입니다. –
감사합니다. '자체'를 추가하십시오. 'resultArray'는 도움이되지 않았습니다. –