Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:37:15+00:00 2026-05-28T05:37:15+00:00

Actually I am Making an Alarm app. In that When i set the Time

  • 0

Actually I am Making an Alarm app. In that When i set the Time The UILocalNotification event happens at that time and it calls the method of AppDelegate class i.e didReceiveNotifications method. In this method i have written a code to call a method of SetViewController (showReminder method) and now in this method i want that it should show a NewViewController i.e TimeViewController as i have to show animation when the Alarm Invokes.

I need this as When Alarm invokes i have setted a Action sheet to appear but i wanted to show animation also.Action sheet appears in all views But the animation can be Shown in only particular view, that’s why i need to show A different ViewController.

Here is the code for what i am trying :-
I have tried al these also like PresentModalViewController, dismissModalViewController, AddSubview, remove superView… but result are negative 🙁 what should i do..?

Almost Whole CODE:–

AppDelegate Class :-

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    if (notification){
        NSLog(@"In did Notification");
        NSString *reminderText = [notification.userInfo objectForKey:kRemindMeNotificationDataKey];
        [viewController showReminder:reminderText];
        application.applicationIconBadgeNumber = 0;
    }
}

setViewController.h :-

@interface SetAlarmViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIActionSheetDelegate>{

    IBOutlet UITableView *tableview;
    IBOutlet UIDatePicker *datePicker;
    IBOutlet UITextField *eventText;
    TPKeyboardAvoidingScrollView *scrollView;

    IBOutlet UINavigationBar *titleBar;
    IBOutlet UIButton *setAlarmButton;
    AVAudioPlayer *player;
    int index;
    The420DudeAppDelegate *appDelegate;
    TimeViewController *viewController;

   IBOutlet UIImageView *animatedImages;

    NSMutableArray *imageArray;
    AVPlayerItem *player1,*player3;
    AVPlayerItem *player2,*player4;
    AVQueuePlayer *queuePlayer;
}
@property (nonatomic, retain) IBOutlet UIImageView *animatedImages;

@property (nonatomic, retain) IBOutlet UITableView *tableview;
@property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
@property (nonatomic, retain) IBOutlet UITextField *eventText;
@property (nonatomic, retain) TPKeyboardAvoidingScrollView *scrollView;

@property(nonatomic, retain) IBOutlet UINavigationBar *titleBar;
@property(nonatomic, retain) IBOutlet UIButton *setAlarmButton;
@property(nonatomic) UIReturnKeyType returnKeyType;  

@property(nonatomic, retain) IBOutlet TimeViewController *viewController;

- (IBAction) scheduleAlarm:(id)sender;
- (void)showReminder:(NSString *)text;
-(IBAction)onTapHome;

-(IBAction)onTapChange:(id)sender;

@end

SetViewController.m :-

@synthesize datePicker,tableview, eventText,titleBar,setAlarmButton,returnKeyType,scrollView,animatedImages,viewController;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [super viewDidLoad];

    appDelegate = (The420DudeAppDelegate *)[[UIApplication sharedApplication] delegate];
    eventText.returnKeyType = UIReturnKeyDone;

    viewController = [[TimeViewController alloc] initWithNibName:@"TimeViewController" bundle:nil];

    NSDate *now = [NSDate date];
    [datePicker setDate:now animated:YES];
    eventText.delegate = self;
    index = 0;

    NSString *path1 = [[NSBundle mainBundle] pathForResource:@"inhale" ofType:@"mp3"];
    NSURL *url1 = [NSURL fileURLWithPath:path1];
    player1 = [[AVPlayerItem alloc]initWithURL:url1];

    NSString *path3 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
    NSURL *url3 = [NSURL fileURLWithPath:path3];
    player3 = [[AVPlayerItem alloc]initWithURL:url3];

    NSString *path2 = [[NSBundle mainBundle] pathForResource:@"exhale" ofType:@"mp3"];
    NSURL *url2 = [NSURL fileURLWithPath:path2];
    player2 = [[AVPlayerItem alloc]initWithURL:url2];

    NSString *path4 = [[NSBundle mainBundle] pathForResource:@"Dude" ofType:@"mp3"];
    NSURL *url4 = [NSURL fileURLWithPath:path4];
    player4 = [[AVPlayerItem alloc]initWithURL:url4];


    NSArray *items = [[NSArray alloc]initWithObjects:player1,player3,player2,player4,nil];
    queuePlayer = [[AVQueuePlayer alloc] initWithItems:items];    

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playEnded) name:AVPlayerItemDidPlayToEndTimeNotification object:player4];



}

-(void)onAlarmInvoke
{
    animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    animatedImages.userInteractionEnabled = YES;
    [animatedImages setContentMode:UIViewContentModeScaleToFill];
    [self.view addSubview : animatedImages];

    [queuePlayer play];    

    // Array to hold jpg images
    imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];

    // Build array of images, cycling through image names
    for (int i = 1; i <= IMAGE_COUNT; i++)
        [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"animation(%d).jpg", i]]];

    animatedImages.animationImages = [NSArray arrayWithArray:imageArray];

    // One cycle through all the images takes 1.0 seconds
    animatedImages.animationDuration = 12.0;

    // Repeat foreverlight electro / 4 sec.
    animatedImages.animationRepeatCount = -1;

    // Add subview and make window visible
    //  [self.view addSubview:animatedImages];

    animatedImages.image = [imageArray objectAtIndex:imageArray.count - 1];

    // Start it up
    [animatedImages startAnimating];



    // Wait 5 seconds, then stop animation
    [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:15000];

}

-(void)playEnded
{   
    [self performSelector:@selector(playNextItem) withObject:nil afterDelay:5.0];
}

-(void)playNextItem
{
    [queuePlayer play];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    [scrollView adjustOffsetToIdealIfNeeded];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    [self.tableview reloadData];
}

- (IBAction) scheduleAlarm:(id)sender {
    [eventText resignFirstResponder];

    // Get the current date
    NSDate *pickerDate = [self.datePicker date];

    //   NSDate *selectedDate = [datePicker date]; // you don't need to alloc-init the variable first
    NSCalendar *cal = [NSCalendar currentCalendar];  
    NSDateComponents *dc = [cal components: (NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:pickerDate];
    pickerDate = [cal dateFromComponents:dc]; 

    NSLog(@"%@ is the date in picker date",pickerDate);

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = pickerDate;
    //  NSLog(@"%@",localNotif.fireDate);
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    //  NSLog(@"%@",localNotif.timeZone);

    // Notification details
    localNotif.alertBody = [eventText text];

    // Set the action button
    localNotif.alertAction = @"Show me";
    localNotif.repeatInterval = NSDayCalendarUnit;
    localNotif.soundName = @"jet.wav";
    // Specify custom data for the notification
    NSDictionary *userDict = [NSDictionary dictionaryWithObject:eventText.text
                                                         forKey:kRemindMeNotificationDataKey];
    localNotif.userInfo = userDict;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

    [self.tableview reloadData];
    eventText.text = @"";

    viewController = [[TimeViewController alloc] initWithNibName:@"TimeViewController" bundle:nil];
    [self presentModalViewController:viewController animated:YES];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    index = indexPath.row;
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning!!!" 
                                                        message:@"Are you sure you want to Delete???" delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Ok",nil];
    [alertView show];
    [alertView release];

}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    UILocalNotification *notify = [notificationArray objectAtIndex:index];

    if(buttonIndex == 0)
    {
        // Do Nothing on Tapping Cancel...
    }
    if(buttonIndex ==1)
    {
        if(notify)
            [[UIApplication sharedApplication] cancelLocalNotification:notify];
    }
    [self.tableview reloadData];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    // Configure the cell...

    NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];

    [cell.textLabel setText:notif.alertBody];
    [cell.detailTextLabel setText:[notif.fireDate description]];    
    return cell;
}

- (void)viewDidUnload {
    datePicker = nil;
    tableview = nil;
    eventText = nil;
    [self setScrollView:nil];
    [super viewDidUnload];

}

- (void)showReminder:(NSString *)text {

    [self onAlarmInvoke];

    [self.view addSubview:viewController.view];

    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Cancel" otherButtonTitles:nil];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    CGRect rect = self.view.frame;
   // if(rect.origin.y <= 480)
  //      rect.origin.y +=20;

    self.view.frame = rect;
    [actionSheet showInView:self.view];
    [actionSheet release];


}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if(buttonIndex == 0)
    {
        [player stop];
        NSLog(@"OK Tapped");
    }
    if(buttonIndex ==  1)
    {
        [player stop];
        NSLog(@"Cancel Tapped");
    }

}

-(IBAction)onTapHome{
    viewController = [[TimeViewController alloc] initWithNibName:@"TimeViewController" bundle:nil];
    [self presentModalViewController:viewController animated:YES];
}

- (void)dealloc {
    [super dealloc];
    [datePicker release];
    [tableview release];
    [eventText release];
    [scrollView release];
}
-(IBAction)onTapChange:(id)sender{

    SetTimeViewController *viewC = [[SetTimeViewController alloc]initWithNibName:@"SetTimeViewController" bundle:nil];
    [self presentModalViewController:viewC animated:YES];
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:37:16+00:00Added an answer on May 28, 2026 at 5:37 am

    Your viewController is probably showing the view, but without the SetViewController’s view on the screen you can’t see it. Your going to have to first go to the SetViewController and then present your TimeViewController. Is this right, you want to show the SetViewController but call the showReminder: method right away? But only from the didReceiveLocalNotification:.

    If this is the case, set a flag,and a text property in your SetViewControllers .h,

    BOOL isFromNotification;
    NSString *notifText; 
    

    and present the SetViewController,and set the flag

    SetViewController *setViewController = [SetViewController alloc]........
    setViewController.isFromNotification = YES;
    setViewController.notifText = reminderText;
    [self presentModalViewController animated:YES}
    

    and then in the viewDidAppear: of SetViewController

    if(isFromNotification = YES){
      [self showReminders:notifText];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I'm actually making an iPhone app with a big library of guitar chords
So I'm making a very basic Twitter app (it's actually Presence 2 from the
Actually my question is all in the title. Anyway: I have a class and
This problem is making me crazy. Actually I have multiple problems. First one: Why
I have several javascript files that during run-time get combined and minified. This is
This may initially seem generic, but in fact, I am actually making the decision
I am making a simple application and will require to actually load different views
I'm currently making a site where i want to implement multi-language version. which actually
I am actually making a unlike button for my website. The code I've used
I have a button which when pressed makes calls that load information from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.