iPhone slide view passing variables
Posted
by sebastyuiop
on Stack Overflow
See other posts from Stack Overflow
or by sebastyuiop
Published on 2010-05-09T12:45:29Z
Indexed on
2010/05/09
12:48 UTC
Read the original article
Hit count: 326
Right, I'm trying to make an app that has a calculation that involves a stopwatch. When a button on the calculation view is clicked a stopwatch slides in from the bottom. This all works fine, the problem I can't get my head around is how to send the recorded time back to the previous controller to update a textfield.
I've simplified the code and stripped out most irrelevant stuff.
Many thanks.
CalculationViewController.h
#import <UIKit/UIKit.h>
@interface CalculationViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITextField *inputTxt;
}
@property (nonatomic, retain) UITextField *inputTxt;
- (IBAction)showTimer:(id)sender;
@end
CalculationViewController.m
#import "CalculationViewController.h"
#import "TimerViewController.h"
@implementation CalculationViewController
- (IBAction)showTimer:(id)sender {
TimerViewController *timerView = [[TimerViewController alloc] init];
[self.navigationController presentModalViewController:timerView animated:YES];
}
TimerViewController.h
#import <UIKit/UIKit.h>
@interface TimerViewController : UIViewController {
IBOutlet UILabel *time;
NSTimer *myTicker;
}
- (IBAction)start;
- (IBAction)stop;
- (IBAction)reset;
- (void)showActivity;
@end
TimerViewController.m
#import "TimerViewController.h"
#import "CalculationViewController.h"
@implementation TimerViewController
- (IBAction)start {
myTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES];
}
- (IBAction)stop {
[myTicker invalidate];
#Update inputTxt on calculation view here
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)reset {
time.text = @"0";
}
- (void)showActivity {
int currentTime = [time.text intValue];
int newTime = currentTime + 1;
time.text = [NSString stringWithFormat:@"%d", newTime];
}
@end
© Stack Overflow or respective owner