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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:06:26+00:00 2026-06-09T21:06:26+00:00

This morning I was looking over some old code I found somewhere (and used

  • 0

This morning I was looking over some old code I found somewhere (and used in an app) that hacks a UIAlertView in order to get one string of input from the user. It’s overkill for the purpose and looks rather silly but I’ve never seen a simpler way. I then came up with the following approach, which seems to work (iPad 5.1.1 and simulator).

My question is a bit open-ended but, essentially, are there conditions under which this breaks as a strategy: create an off-screen text field with an accessory view, put a proxy text field in the accessory view, and forward various property settings to the proxy?

PMKeyboardTextField.h:

#import <UIKit/UIKit.h>

@interface PMKeyboardTextField : UITextField
- (id)initWithPrompt:(NSString *)prompt;
@end

PMKeyboardTextField.m:

#import "PMKeyboardTextField.h"

@interface PMKeyboardTextField ()
@property (nonatomic, strong) UITextField *inputField;
@end

@implementation PMKeyboardTextField
@synthesize inputField = _inputField;

- (id)initWithPrompt:(NSString *)prompt {
    self = [super initWithFrame:CGRectMake(-1, -1, 1, 1)];
    if (self) {
        UIView *accessory =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 72)];
        [accessory setBackgroundColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8]];

        UILabel *getLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 8, 284, 21)];
        [getLabel setBackgroundColor:[UIColor clearColor]];
        getLabel.text = prompt;
        [accessory addSubview:getLabel];

        self.inputField = [[UITextField alloc] initWithFrame:CGRectMake(18, 37, 264, 31)];
        [accessory addSubview:self.inputField];

        self.inputAccessoryView = accessory;
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardDidShow)
                                                     name:UIKeyboardDidShowNotification
                                                   object:nil];
    }
    return self;
}

- (void)keyboardDidShow {
    [self.inputField becomeFirstResponder];
}

- (id<UITextFieldDelegate>)delegate {
    return self.inputField.delegate;
}

- (void)setDelegate:(id<UITextFieldDelegate>)delegate {
    self.inputField.delegate = delegate;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@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-06-09T21:06:28+00:00Added an answer on June 9, 2026 at 9:06 pm

    As much as I like this idea for its ability to avoid the excess clutter of an alert view or the need to reposition on-screen views, the fatal flaw was pointed out to me in another forum: some people use external keyboards!

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

Sidebar

Related Questions

This morning we found an old chunk of code that was causing a library
I came across this strange looking declaration in some code early this morning (before
This morning in my CS lab, I was compiling and executing some C code.
This morning, I tried to commit a revision to Subversion and found that all
Good morning. I have been looking all over trying to answer this question. If
I was just doing some random testing on locking in multi-threading this morning and
Good morning. I've been having this issue for some days and have been lokking
So this morning I posted a confused question about assembly and I received some
Morning all, I know that this sounds like a simple referencing problem from the
This morning I stumbled over a weird issue in Visual Studio's Windows Forms designer.

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.