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 6796705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:31:12+00:00 2026-05-26T18:31:12+00:00

I posted a question the other day, but I didn’t included enough code and

  • 0

I posted a question the other day, but I didn’t included enough code and I’m having a further problem. I’m not sure if I should be using [[UIApplication sharedApplication] windows], but since the fix I was advise to make the other day the array doesn’t have the correct amount of values.

Can someone advise / show me where I’m going wrong and if its correct to use [[UIApplication sharedApplication] windows] ?

- (void) addDoneToKeyboard {

    doneButton.hidden =  NO;

    //Add a button to the top, above all windows
    NSArray *allWindows = [[UIApplication sharedApplication] windows];
    NSUInteger topWindowIndex = [allWindows count];// fix - 1;
    UIWindow *topWindow = [allWindows objectAtIndex:topWindowIndex]; //SIGABRT

Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘ -[NSMutableArray objectAtIndex:]: index 2 beyond bounds [0 .. 1]’

    // check if top window is of keypad or else
    NSString *topViewClassName = [NSString stringWithFormat:@"%@", 
             [topWindow class]];
    while (![topViewClassName isEqualToString:@"UITextEffectsWindow"] ) {
        --topWindowIndex;

        if(topWindowIndex < 1) // fix 0
            break;

        topWindow = [allWindows objectAtIndex:topWindowIndex];
        topViewClassName = [NSString stringWithFormat:@"%@", [topWindow class]];
    }

//

    if(topWindowIndex < 1) { // fix 0
        topWindowIndex = [allWindows count] - 1;
        topWindow = [allWindows objectAtIndex:topWindowIndex];
    }

    if (doneButton.superview)
        [doneButton removeFromSuperview];

    [topWindow addSubview:doneButton];

    if (!doneButtonShownRecently) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDuration:SLIDE_IN_ANIMATION_DURATION];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        doneButton.frame = CGRectMake(0, 480-53, 
                         doneButton.frame.size.width, 53);
        [UIView commitAnimations];
    } else {
        doneButton.frame = CGRectMake(0, 427, 
                         doneButton.frame.size.width, 53);
    }

    doneButtonShown = YES;
}
  • 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-26T18:31:13+00:00Added an answer on May 26, 2026 at 6:31 pm

    Your code comments here appear to already tell you what you need to do:

    NSUInteger topWindowIndex = [allWindows count] - 1;  
    UIWindow *topWindow = [allWindows objectAtIndex:topWindowIndex];
    

    Counting starts with 1, while array indexes start at 0—your two array index values are 0 (for your first window) and 1 (for your second window) but you were trying to access index value 2.

    Edit: Note the following code is now completely redundant in the above:  

    if(topWindowIndex < 1) { // fix 0
    topWindowIndex = [allWindows count] - 1;
    topWindow = [allWindows objectAtIndex:topWindowIndex];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted a similar question the other day asking what my command path is.
i posted a question like this yesterday but I was not clear in the
I posted a question re LDAP account management, but after exploring this, it's not
I have posted similar question previously, but this time I am providing some code
As there's no response to the other question and I'm not sure if it
I have had a long problem with this code. I have posted this question
i posted the other day with practice questions i was getting stuck with and
I posted this question: https://stackoverflow.com/questions/418597/java-and-net-for-php-programmer and the answers I was given didn't really help
I posted this question on Reddit Programming and did not get a single response.
I've seen similar question posted on two other places. Spotify apps / home directory

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.