Giter Site home page Giter Site logo

alokchauve / ddalertprompt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jkubicek/ddalertprompt

1.0 2.0 0.0 279 KB

DDAlertPrompt is an UIAlertView subclass provides UITextFields for user/password inputs

Home Page: http://digdog.tumblr.com/post/1483470206/two-licenses-one-domain

ddalertprompt's Introduction

DDAlertPrompt for iOS

DDAlertPrompt is an UIAlertView subclass provides UITextFields for user/password inputs

Features

  1. Looks similar to the undocumented/private UIAlertView's built-in UITextField.
  2. Better UITextField alignment.
  3. Support orientations.
  4. No private API calls.

Issue

If you look closely in source code, there's a bug in UIAlertView subclass. If UIAlertView contains UITableView with UITextField as UITableViewCell's contentView subview. When UITextField becomes first responder, keyboard shows up, delegate called, able to paste text, but characters you typed from keyboard won't show up in UITextField.

Override private api seems fixed the problem:

-(BOOL)_needsKeyboard {
    // Private API hack by @0xced (Cedric Luthi) for keyboard responder issue: http://twitter.com/0xced/status/29067229352
    return [UIDevice instancesRespondToSelector:@selector(isMultitaskingSupported)];
}

but if you don't want to use private api, you can try:

// FIXME: If you uncomment below, UITextFields in tableview will show characters when typing (keyboard reponder issue).
[self addSubview:self.plainTextField];

Feedback from DTS

And according to Apple DTS (this cause one ticket, btw):

On Nov 1, 2010, at 1:56 PM, Apple Developer Technical Support wrote:

Thank you for your inquiry to Apple Worldwide Developer Technical Support.

UIAlertView isn't really well equipped to handle custom subviews, and is instead intended to be used "as is". Additionally, there is the potential danger that if the subview hierarchy for UIAlertView changes in the future, applications that add their own subviews to UIAlertView could break. In this case, my guess is that there may be some sort of conflict between your UITableView and the underlying UITableView that UIAlertView may create/use automatically in some situations.

The general recommended approach is to use a modal view controller that resembles an alert view if it is serving the same sort of purpose. It's not uncommon to want more customization for UIAlertView, however, so please feel free to log a request at http://developer.apple.com/bugreporter to let iOS engineering know that you're being impacted by this.

Dxxxxx Yx
DTS Engineer, Apple Worldwide Developer Relations

This is not a good use of UIAlertView subclassing, please be informed.

And this bug is filed under radar://8617447.

Update from Apple: It's an Known Issue.

On Nov 17, 2010, at 4:34 PM, [email protected] wrote:

This is a follow up to Bug ID# 8617447. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 8639186. The original bug number being used to track this duplicate issue can be found in the State column, in this format: Duplicate/OrigBug#.

Thank you for submitting this bug report. We truly appreciate your assistance in helping us discover and isolate bugs.

Best Regards,

Pxxxxxk Cxxxxxs
Apple Developer Connection
Worldwide Developer Relations

Compare

Thanks to 0xced (Cedric Luthi, http://github.com/0xced), you can compare built-in and general subclass with DDAlertPrompt:

  1. The undocumented/private UIAlertView's built-in

  2. General UIAlertView subclass with grouped UITableView

Requirement

  1. iOS SDK 4. Haven't test on iOS 3, but should be okay. Demo project uses 4.2b3 SDK.

Usage

Create DDAlertPrompt like normal UIAlertView:

DDAlertPrompt *loginPrompt = [[DDAlertPrompt alloc] initWithTitle:@"Sign in to Service" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitle:@"Sign In"];	
[loginPrompt show];
[loginPrompt release];

Implement -didPresentAlertView: UIAlertViewDelegate like this to bring up keyboard:

- (void)didPresentAlertView:(UIAlertView *)alertView {
	if ([alertView isKindOfClass:[DDAlertPrompt class]]) {
		DDAlertPrompt *loginPrompt = (DDAlertPrompt *)alertView;
		[loginPrompt.plainTextField becomeFirstResponder];		
		[loginPrompt setNeedsLayout];
	}
}

And get the text from -alertView:willDismissWithButtonIndex: UIAlertViewDelegate:

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
	if (buttonIndex == [alertView cancelButtonIndex]) {
	} else {
		if ([alertView isKindOfClass:[DDAlertPrompt class]]) {
			DDAlertPrompt *loginPrompt = (DDAlertPrompt *)alertView;
			NSLog(@"textField: %@", loginPrompt.plainTextField.text);
			NSLog(@"secretTextField: %@", loginPrompt.secretTextField.text);
		}
	}
}

Screenshots

License

DDAlertPrompt is released under MIT license.

ddalertprompt's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.