в вашем saveShift:(id)sender
методе вам нужно много кода.
Просто сделайте следующее:
[self.myTableInfo addObject:@"SecondViewConroller dimissed"];
[self dismissModalViewControllerAnimated:YES];
В этом коде я предполагаю, что вы передали ссылку на свой NSMutableArray в вашем secondView.
Я помню ваш пост из NSMutableArray, и вы представляете SecondView из FirstView (если у меня хорошая память).
Но в вашем коде, в saveShift
secondView, вы в настоящее время создаете brand new
FirstView, который отличается от того, откуда вы пришли. Поэтому, когда вы отклоняете модальное представление, ваш «совершенно новый» firstView теряется, и вы возвращаетесь к своему первоначальному firstView. И этот последний не слышал о вашем объекте.
Привет, Сэм,
посмотрите на последний ответ, который я дал вам в вашей ветке NSMutableArray, там есть почти все, что вам нужно для решения этой проблемы.
ОК, вот еще быстрое исправление, чтобы оно могло работать
// SecondViewController.m
#import "SecondViewController.h"
#import "FirstViewController.h"
@implementation SecondViewController
@synthesize dateformatter,mydatepicker,startingTime;
// HERE Add a new property that match this and a variable in the .h
@synthesize array4Test;
// HERE make an init that will make this UIViewController know about your NSMutableArray
- (id)initWithMutableArray:aMutableArray
{
self = [self initWithNibName:nil bundle:nil];
if (self)
{
self.array4Test = aMutableArray;
}
return self;
}
- (void)dealloc
{
// HERE clean up
self.array4Test = nil;
[super dealloc];
}
-(IBAction)saveShift:(id)sender{
// HERE remove this code
//FirstViewController *firstViewController = [[FirstViewController alloc]init];
//[firstViewController.mytableinfo addObject:@"Hello world"];
//NSLog(@"%@",[firstViewController.mytableinfo objectAtIndex:0]);
// HERE add an object to the mutableArray that is store in your firstViewController, the one you've passed the reference in
[self.array4Test addObject:@"This is a String"];
[self dismissModalViewControllerAnimated:YES];
}
Я думаю, что я только что добавил NSLog () в этом.
// FirstViewController.m
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation FirstViewController
@synthesize mytableinfo,mytableview;
@synthesize goneToOtherView;
-(IBAction)addShift:(id)sender{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithMutableArray:self.mytableinfo];
[self presentModalViewController:secondViewController animated:YES];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.mytableview reloadData];
NSString *aString = [mytableinfo lastObject];
if (aString)
{
NSLog(@"This just came back from the second View\n%@", aString);
}
}