0
我一直在頭撞我的桌子一個小時。我需要獲取從一個視圖控制器傳遞到下一個視圖控制器的詳細信息,然後在顯示視圖之前更新視圖。對我而言,我無法正常工作。這裏是我使用的代碼:在顯示之前獲取_detailItem和更改標籤數據
VC#1(通過從數據):
-(IBAction)NotOwed:(id)sender{
InputViewController *input = [[InputViewController alloc]init];
self.tdModal = input;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
InputViewController *viewController = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self presentViewController:viewController animated:YES completion:nil];
[self.tdModal setDetailItem:@"NotOwed"];
// do any setup you need for myNewVC
[self dismissSemiModalViewController:self];
}
-(IBAction)Owed:(id)sender{
InputViewController *input = [[InputViewController alloc]init];
[self.tdModal setDetailItem:@"Owed"];
self.tdModal = input;
[input setDetailItem:@"Owed"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
InputViewController *viewController = (InputViewController *)[storyboard instantiateViewControllerWithIdentifier:@"VDI"];
[self presentViewController:viewController animated:YES completion:nil];
// do any setup you need for myNewVC
[self dismissSemiModalViewController:self];
}
VC#2(數據):
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
NSLog(@"THIS: %@", _detailItem);
[self configureView];
}
}
- (void)viewDidLoad
{
[oField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
[iField addTarget:self action:@selector(textFieldChanged:) forControlEvents:UIControlEventEditingChanged];
[super viewDidLoad];
id delegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [delegate managedObjectContext];
UIView *fixItView = [[UIView alloc] init];
fixItView.frame = CGRectMake(0, 0, 320, 20);
fixItView.backgroundColor = [UIColor blackColor]; //change this to match your navigation bar
[self.view addSubview:fixItView];
// Do any additional setup after loading the view.
UIDatePicker *picker = [[UIDatePicker alloc] init];
picker.datePickerMode = UIDatePickerModeDate;
dueField.inputView = picker;
[picker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
if ([[_detailItem description] isEqual: @"Owed"]){
iLabel.hidden = true;
oLabel.hidden = true;
mLabel.text = @"owes me the sum of";
}else{
iLabel.hidden = false;
oLabel.hidden = false;
mLabel.text = @"the sum of";
}
}
}
- (IBAction)submit:(id)sender
{
UIDatePicker *picker = (UIDatePicker*)dueField.inputView;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSString *editedMoney = [[NSString alloc]init];
[formatter setDateFormat:@"ddMMyyyy"];
[formatter setDateStyle:NSDateFormatterFullStyle];
NSDate *dt = picker.date;
NSString *dateAsString = [formatter stringFromDate:dt];
dateOwed = YES;
id delegate = [[MasterViewController alloc] init];
self.managedObjectContext = [delegate managedObjectContext];
if ([_detailItem isEqual: @"Owed"]) {
editedMoney = [NSString stringWithFormat:@"+$%@", oField.text];
}else{
editedMoney = [NSString stringWithFormat:@"-$%@", oField.text];
}
MasterViewController *topViewController = [[MasterViewController alloc]init];
topViewController.managedObjectContext = self.managedObjectContext;
NSString *wow = [[NSString alloc]init];
if(oLabel.hidden == true){
wow = @"someoneowes";
}else{
[email protected]"nope";
}
MasterViewController *master = [[MasterViewController alloc]init];
bool OwedYes = dateOwed;
[master setData:iField.text :editedMoney :picker.date :OwedYes :wow :dateAsString];
NSManagedObjectContext *context = [self managedObjectContext];
[UIView beginAnimations:@"LeftFlip" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view.superview cache:YES];
[UIView commitAnimations];
[self dismissViewControllerAnimated:YES completion:nil];
[self.view.superview removeFromSuperview];
NSLog(@"TEH %@", context);
}
的的NSLog上的VC#頂部2報告正確的字符串,但如果我嘗試使用或比較字符串,它似乎不工作。
對您的嚴重榮譽!謝謝! – 128keaton
沒關係。有時候你看不到它,一雙新鮮的眼睛直視着它 – Paulw11