From 5b4ae316e212049e7d86a4e669a33d0f9752b923 Mon Sep 17 00:00:00 2001 From: Stefan Sturm Date: Mon, 2 Mar 2015 14:19:36 +0100 Subject: [PATCH] ADD public method to change the message text --- CSNotificationView/CSNotificationView.h | 4 ++++ CSNotificationView/CSNotificationView.m | 8 ++++++++ .../CSRootViewController.m | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CSNotificationView/CSNotificationView.h b/CSNotificationView/CSNotificationView.h index b8dd36d..27382a6 100755 --- a/CSNotificationView/CSNotificationView.h +++ b/CSNotificationView/CSNotificationView.h @@ -62,6 +62,10 @@ typedef void(^CSVoidBlock)(); - (void)dismissWithStyle:(CSNotificationViewStyle)style message:(NSString*)message duration:(NSTimeInterval)duration animated:(BOOL)animated; @property (readonly, nonatomic, getter = isShowing) BOOL visible; +#pragma mark - updates + +- (void)updateMessage:(NSString *)message; + #pragma mark - visible properties /** diff --git a/CSNotificationView/CSNotificationView.m b/CSNotificationView/CSNotificationView.m index 4c251aa..5d27855 100644 --- a/CSNotificationView/CSNotificationView.m +++ b/CSNotificationView/CSNotificationView.m @@ -377,6 +377,14 @@ - (void)dismissWithStyle:(CSNotificationViewStyle)style message:(NSString *)mess }]; } +#pragma mark - updates + +- (void)updateMessage:(NSString *)message +{ + self.textLabel.text = message; +} + + #pragma mark - frame calculation //Workaround as there is a bug: sometimes, when accessing topLayoutGuide, it will render contentSize of UITableViewControllers to be {0, 0} diff --git a/Example/CSNotificationViewDemo/CSRootViewController.m b/Example/CSNotificationViewDemo/CSRootViewController.m index fdb5517..b802de5 100755 --- a/Example/CSNotificationViewDemo/CSRootViewController.m +++ b/Example/CSNotificationViewDemo/CSRootViewController.m @@ -73,7 +73,7 @@ - (IBAction)showPermanent:(id)sender self.permanentNotification = [CSNotificationView notificationViewWithParentViewController:self.navigationController tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1] - image:nil message:@"I am running for two seconds."]; + image:nil message:@"I am running for five seconds."]; [self.permanentNotification setShowingActivity:YES]; @@ -89,8 +89,14 @@ - (IBAction)showPermanent:(id)sender style:UIBarButtonItemStyleDone target:weakself action:@selector(cancel)]; + + weakself.navigationItem.leftBarButtonItem = + [[UIBarButtonItem alloc] initWithTitle:@"Update" + style:UIBarButtonItemStyleDone + target:weakself + action:@selector(update)]; - double delayInSeconds = 2.0; + double delayInSeconds = 5.0; dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [weakself success]; @@ -99,8 +105,14 @@ - (IBAction)showPermanent:(id)sender }]; } +- (void)update +{ + [self.permanentNotification updateMessage:@"This is a new message..."]; +} + - (void)cancel { + self.navigationItem.leftBarButtonItem = nil; self.navigationItem.rightBarButtonItem = nil; [self.permanentNotification dismissWithStyle:CSNotificationViewStyleError message:@"Cancelled" @@ -111,6 +123,7 @@ - (void)cancel - (void)success { + self.navigationItem.leftBarButtonItem = nil; self.navigationItem.rightBarButtonItem = nil; [self.permanentNotification dismissWithStyle:CSNotificationViewStyleSuccess message:@"Sucess!"