Created
December 13, 2012 00:12
-
-
Save soundsmitten/4272911 to your computer and use it in GitHub Desktop.
Objective-C: Example of Passing info from ViewController back to PreviousViewController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AddViewController- has fields where data is entered. | |
AddViewController.h | |
@protocol AddDelegate <NSObject> | |
-(void) saveMySeconds: (int) seconds andTitle: (NSString*)activity; | |
@end | |
//AddViewController.m | |
#pragma mark text field delegate method | |
-(BOOL)textFieldShouldReturn:(UITextField *)textField { // dismiss keyboard on return. | |
[textField resignFirstResponder]; | |
return YES; | |
} | |
- (IBAction)SaveAction:(id)sender { | |
NSTimeInterval duration = (NSTimeInterval)TimePicker.countDownDuration; | |
NSString * myTitle = ActivityPicker.text; | |
int seconds = (int) duration; | |
[self.addDelegate saveMySeconds:seconds andTitle: myTitle]; | |
[self.navigationController popViewControllerAnimated:YES]; | |
} | |
// SetupViewController.m- This is the previous View Controller | |
#pragma mark AddDelegate Implementation | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
{ | |
NSLog(@"id %@", [segue destinationViewController]); | |
AddViewController *vcb = (AddViewController *)[segue destinationViewController]; | |
vcb.addDelegate = self; //key point | |
} | |
// implement saveMySeconds | |
- (void) saveMySeconds:(int)seconds andTitle:(NSString *)activity { | |
NSLog(@"Made It to the delegate implementation"); | |
NSLog(@"%i, %@", seconds, activity); | |
TimerU * u = [[TimerU alloc]init]; | |
[timer addSegment:u withDuration:seconds andTitle:activity]; | |
u.remainingInSegment = u.unitDuration; | |
myArray = [timer timerArr]; | |
NSLog(@"Count: %i, Array: %@",[myArray count], myArray); | |
int totalDuration = [timer calculateDuration]; | |
NSLog(@"%i", totalDuration); | |
NSString * formattedDuration = [self formatSeconds: totalDuration]; | |
lblTotalCountdown.text = formattedDuration; | |
[tblSetup reloadData]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment