請幫助,我需要做些什麼來保留我的數組'resultArray'中的對象?我用「保留」,但沒有幫助。當在'doMyAction'中訪問數組時,數組具有對象,然後執行「performSegueWithIdentifier」,它連接到try2FlipsideViewController,我嘗試訪問第一個控制器中定義的「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
#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 = ...'?因爲否則你繞過可能導致你的問題的setter。 –
謝謝,加入'自我'。到'resultArray'沒有幫助。 –