Permalink
Browse files

Disable loadMessageBoard timer when view did disappear

  • Loading branch information...
Ernesto Vargas
Ernesto Vargas committed Feb 17, 2012
1 parent 796678e commit c42fbf4f902b05af9f1b4e1f3eaf754c0642f8d3
@@ -12,6 +12,8 @@
@implementation MessageViewController
@synthesize scrollView = _scrollView;
+NSTimer *timer;
+
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
@@ -32,7 +34,7 @@ - (void)loadMessageBoard {
- (void)viewDidLoad
{
- // When view did load, create table and load message board
+ // When view did load, Map message, create table and load message board
[super viewDidLoad];
self.scrollView.frame = CGRectMake(0, 0, 320, 460);
@@ -44,9 +46,7 @@ - (void)viewDidLoad
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.scrollView addSubview:_tableView];
- [self loadMessageBoard];
-
-
+
// Message Mapping
RKObjectMapping* actorMapping = [RKObjectMapping mappingForClass:[UGActor class]];
[actorMapping mapAttributes:@"displayName", @"picture", nil];
@@ -59,8 +59,7 @@ - (void)viewDidLoad
[[RKObjectManager sharedManager].mappingProvider setMapping:messageMapping forKeyPath:@"entities"];
- // Load message board every 5 seconds
- [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(loadMessageBoard) userInfo:NULL repeats:YES];
+ [self loadMessageBoard];
}
- (void)viewDidUnload
@@ -78,6 +77,8 @@ - (void)viewWillAppear:(BOOL)animated
- (void)viewDidAppear:(BOOL)animated
{
+ // Load message board every 5 seconds
+ timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(loadMessageBoard) userInfo:NULL repeats:YES];
[super viewDidAppear:animated];
}
@@ -88,6 +89,9 @@ - (void)viewWillDisappear:(BOOL)animated
- (void)viewDidDisappear:(BOOL)animated
{
+ if (timer) {
+ [timer invalidate];
+ }
[super viewDidDisappear:animated];
}

0 comments on commit c42fbf4

Please sign in to comment.