Entering Text Using Pop-up in IOS 7 - ios

I have an app that was built on Xcode 4.6 and iOS 6. I am now upgrading it to iOS 7 using XCode 5.
I have this code that worked perfectly on iOS 6. What it does it bring a popup with UITextField in it. User can enter whatever text they want and hit OK. I take their text and put it in a UILabel.
The problem I have is that in iOS 7 when I bring up this pop-up text box, its not editable. Touching it doesn't do anything. How come?
Here is the code and screenshot
// ************
// ENTER TEXT
// ************
-(IBAction)insertText
{
UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:#"Enter Text \n"
message:#"\n\n Keep it short and sweet"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK", nil];
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
[dialog show];
}

Use the provided API instead this hack. Instead of adding your own text field (which was never actually supported), set the alert view's alertViewStyle to UIAlertViewStylePlainTextInput. This will give you a supported text entry field in the alert view.

Related

Why my UIActionSheet suddenly cutoff at the bottom of the device (iOS 8)?

I have some very standard code for UIActionSheet that works well on production.
-(void) showGameMenu
{
UIActionSheet * const activeSheet = [[UIActionSheet alloc] initWithTitle:#"Game"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"New Game", #"Save Game", #"Load Game", #"Email Game", #"Share Position", #"Setup Position", nil];
[activeSheet setTag:Framework::GameMenuButton];
[self showActionSheetOnToolbar:activeSheet];
}
-(void) showActionSheetOnToolbar:(UIActionSheet *)sheet
{
[sheet showFromBarButtonItem:_gameItem animated:YES];
}
_gameItem is not nil and is a proper UIBarButtonItem for the "Game" item as shown in the screenshot. The code has been working well on production until recently I tried to compile the same project with iOS 8 (it was compiled with iOS 7).
Suddenly, the menu got cut-off around the bottom edge of the device. Furthermore, there was a transparent black-thing covered about 3/4 of the screen horizontally.
I have no clue why this happens and not sure how to fix it.
Are you using auto-layout?
I am not sure but it can be about constraints.I say this because your "Game" and "Flip" buttons look smaller than what you expected.
So I recommend you to delete constraints on your view to your main view and add them again without checking "constrain to margins" via "pin" menu from bottom.
If this is not the case please add what you see in iOS 7.

Action Sheet Button text alignment

I am using actionsheet, and I have added unicode symbol. But my button title is not centered. I want the unicode symbol to be located at right most. If you think that it is impossible, can I use flag image separately rather than using unicode symbol ? If yes, how could I add image next to the button title?
UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:#"Would you like to see ozone cloud in your area or a trace of your walking/driving/biking activity" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"OzoneMap",#"ParticleMap", #"TraceMap \U0001F6A9", nil];
[[[actionsheet valueForKey:#"_buttons"] objectAtIndex:0] setImage:[UIImage imageNamed:#"play2.png"] forState:UIControlStateNormal];

Can i put multiple text boxes in an alert box in ios?

can I put multiple text input boxes on the alert box in iOS?
The best solution is to write or use a custom alert view that has the text fields that you need. If you only need 1 text field (or username/password) you can still use UIAlertView by setting the alertViewStyle property.
There are custom alert views already written, such as this one.
Yes, that's possible.
Just add UITextField as subviews to the UIAlertView.
Set the tag for each UITextField, in order to retrieve the entered text later.
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
textField1.tag=0;
textField1.borderStyle=UITextBorderStyleRoundedRect;
textField1.delegate=self;
[alert addSubview:textField1];
UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
textField2.tag=1;
textField2.delegate=self;
textField2.borderStyle=UITextBorderStyleRoundedRect;
[alert addSubview:textField2];
[alert show];
PLEASE NOTE that this is bad practice as it relies on UIAlertView being a subclass of UIView. As pointed out by MusiGenesis below, it won't work from iOS 7 onwards.
Hope that helps.
if you want 2 text boxes, you can use login style, but set second item secureTextEntry to NO, refer to
http://forums.macrumors.com/threads/uialertviews-with-textfields.1355954/

UIAlertView with 3 textfields and 3 labels overlap each other

I'm trying to create an UIAlertView with 3 TextFields and 3 Labels.
But with my current code they just go over each other, I've tried to change the frame of the AlertView and I've tried to use the CGAffineTransform but they both didn't work.
Here's my code:
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Sign in" message:#"\n\n\n\n\n" delegate:self cancelButtonTitle:#"Stop" otherButtonTitles:#"Sign in",nil];
UILabel *customerIdLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 55, 65, 21)];
customerIdLabel.tag =1;
customerIdLabel.text = #"Customer id: ";
[myAlertView customerIdLabel];
UITextField *customerIdField = [[UITextField alloc] initWithFrame:CGRectMake(89, 50, 160, 30)];
customerIdField.tag = 2;
customerIdField.placeholder = #"Fill in your customer id";
[myAlertView customerIdField];
And then there's two more combinations of those.
Here's the transform that I've tried:
CGAffineTransform myTransform = CGAffineTransformMakeScale(1.0, 0.5f);
[myAlertView setTransform:myTransform];
And this is what I get:
I'm pretty sure you aren't supposed to use UIAlertViews like that. You're supposed to set the title, message, etc and use the [alertview show]. The documentation seems to be pretty clear that it is an as-is class.The UIAlertViewStyle may be something you can look at, but the options are 1 text field, 1 secure field, or a username and password field.
Your best option is to use a new UIViewController and use the presentViewController:animated:completion: call.
I get around this by not changing UIAlertView but add a clear view on top of it when it is showing (you can pad with spaces) and add the textfields there at the correct location (note when rotation occurs). Then, let the tap go through the view to the UIAlertView. This has gone through Apple in 3 apps in the store.
Before the new SDK in xcode 5 you where able to add subviews to an alert view but that doesn't work anymore. I had to update an app because of that nasty code. Is better to use uipopovercontroller for ipad or show a UIView or even present a viewcontroller for either ipad or iphone.

How do I move down the buttons in UIAlertView?

I have three buttons and a textview in uialertview, and tried to move down the buttons with add "\n" in uialertview's message property. But it's not work. The string will become "..." when it reach the limit of a line. the textview always cover my buttons. Do you have any suggestions? Sorry that I don't have the right to post image.
- (void)addMessage
{
self.addMessageAlertView = [[UIAlertView alloc] initWithTitle:#"Add Title"
message:#"\n\n\n\n function normal function normal function normal function normal function normal "
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"OK",#"Search", nil];
self.addMessageTextView = [[UITextView alloc] initWithFrame:CGRectMake(10.0, 75, 260.0, 25*2)];
[addMessageTextView setBackgroundColor:[UIColor whiteColor]];
addMessageTextView.font = [UIFont systemFontOfSize:20];
addMessageTextView.delegate=self;
addMessageTextView.layer.masksToBounds=YES;
addMessageTextView.layer.cornerRadius=10.0;
addMessageTextView.layer.borderWidth=0.0;
[addMessageAlertView addSubview:addMessageTextView];
[addMessageAlertView show];
[addMessageAlertView release];
[addMessageTextView release];
}
- (void)willPresentAlertView:(UIAlertView *)openURLAlert
{
[openURLAlert setFrame:CGRectMake( 10, 60, 300, 300 )];
[openURLAlert setBounds:CGRectMake(0, 10, 290, 290 )];
}
UIAlert view has maximum height (I've tried this same thing with no success); you won't be able to make it bigger. I suggest that you use a custom pop-over instead. A popover can act like an alert but will give you more flexibility.
This question has some links to tutorials: Are there examples of how to use UIPopoverController on iOS?

Resources