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

  • SEARCH
  • Home
  • 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 7596891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:01:50+00:00 2026-05-30T22:01:50+00:00

I am trying to programmatically create a UIViewController subclass whose view includes some buttons,

  • 0

I am trying to programmatically create a UIViewController subclass whose view includes some buttons, and then add that to a UINavigationController. When I do, you have to touch about 40 or 50 points above each button in order to trigger it (touching the buttons themselves does nothing). The distance between the button and the actual area you have to touch seems to match the height of the UINavigationController’s nav bar, so I suspect that has something to do with it. Any suggestions on how to fix this? Here is the code that creates the window and the buttons (from my UIViewController subclass):

- (void)loadView
{
    ...

    UIWindow* mainView = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
    [mainView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
    [mainView makeKeyAndVisible];

    [self setView:mainView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton* encryptButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [encryptButton setTitle:@"Encrypt" forState:UIControlStateNormal];
    [encryptButton setFrame:CGRectMake(([[self view] bounds].size.width - 150.0f)/2.0f,
                                           ([[self view] bounds].size.height - 120.0f)/2.0f, 150.0f, 40.0f)];
    [encryptButton setBounds:CGRectMake(0.0f, 0.0f, 150.0f, 40.0f)];
    [encryptButton addTarget:self action:@selector(encryptPressed:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:encryptButton];
    [encryptButton release];

    UIButton* decryptButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [decryptButton setTitle:@"Decrypt" forState:UIControlStateNormal];
    [decryptButton setFrame:CGRectMake(([[self view] bounds].size.width - 150.0f)/2.0f,
                                           ([[self view] bounds].size.height - 120.0f)/2.0f + 80.0f, 150.0f, 40.0f)];
    [decryptButton addTarget:self action:@selector(decryptPressed:) forControlEvents:UIControlEventTouchUpInside];
    [[self view] addSubview:decryptButton];
    [decryptButton release];
}

Here’s the code that sets up the UINavigationController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    UUMainWindowViewController* mainWinController = [[UUMainWindowViewController alloc] init];

    UINavigationController* mainNavController = [[UINavigationController alloc]
                                                     initWithRootViewController:mainWinController];
    [mainNavController navigationBar].barStyle = UIBarStyleBlack;
    [self.window setRootViewController:mainNavController];

    [self.window makeKeyAndVisible];
    return 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-30T22:01:51+00:00Added an answer on May 30, 2026 at 10:01 pm

    Figured out my own answer. Turns out this was a newbie mistake where I was constructing a UIWindow in my UIViewController when I really just need to construct a UIView instead. Apparently there should only ever be one UIWindow, so presumably this wasn’t working because UIWindow was assuming it had the entire screen real estate to itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a view programmatically. The result that i want to have
I am trying to create UIViewController programmatically for ModalView presentation on the main window
I'm trying to create a UISearchDisplayController programmatically. I have a method which should set
I am trying to create programmatically a uitableview that can scroll and fit based
I'm trying to create a custom editor for my UIViewController. It was suggested that
I'm trying to dynamically and programmatically create ImageButtons and add them to my Scrolling
I am trying to programmatically create a view controller. I would like to know
I'm trying to create a FrameLayout programmatically as follows(this view will float on the
Trying to programmatically add a splash image that hangs around for a specified amount
i'm trying to create buttons programmatically on my android application depending on how many

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.