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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:56:08+00:00 2026-05-17T01:56:08+00:00

I am trying to add uitextfield to my alterview . When the user tries

  • 0

I am trying to add uitextfield to my alterview. When the user tries to enter text the alterview is supposed to shift up a little bit so the keyboard does not overlap and when pressing the done key the keyboard is supposed to disappear and the alertview should shift back.

It all works fine when run it in iOS 3.1.2 (and also in 3.2) but as soon as I try to run it under iOS 4 the alertview is displayed in the wrong position and the keyboard won’t disappear. Any suggestions? Here is my code:

- (void)addItemAction{

workoutName = [[UIAlertView alloc] initWithTitle:@"New Workout" message:@"Insert the name of your new workout:\n                " delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Done", nil];
workoutName.cancelButtonIndex = 0;
UITextField *titleField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 90.0, 260.0, 25.0)];
titleField.delegate = self;
titleField.borderStyle = UITextBorderStyleRoundedRect;
titleField.returnKeyType = UIReturnKeyDone;
[workoutName addSubview:titleField];
[workoutName show];


}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {


[textField resignFirstResponder];
return YES;

}

- (void)textFieldDidBeginEditing:(UITextField *)textField {

[UIView beginAnimations:nil context:NULL];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, -70.0);
[workoutName setTransform:myTransform];
[UIView commitAnimations];

}

- (void)textFieldDidEndEditing:(UITextField *)textField {

[UIView beginAnimations:nil context:NULL];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 0.0);
[workoutName setTransform:myTransform];
[UIView commitAnimations];
self.newWorkout = textField.text;

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

if (buttonIndex == 1) {
    if (self.newWorkout != @"TestWorkout"){
    [self.workoutPlanArray insertObject:[NSDictionary dictionaryWithObjectsAndKeys:self.newWorkout, @"titleValue", @"04.08.10", @"dateValue", nil] atIndex:counter];
    counter++;
    [self.tableView reloadData];
    }
}


}
  • 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-17T01:56:08+00:00Added an answer on May 17, 2026 at 1:56 am

    I am also using alertview with a textfield in my application, & that too on ioS 4.0.
    Its working fine.

    Here is the sample code:_

    -(void)showAlert{
    
    showAlert=YES; //boolean variable
    
    createNewAlert =[[UIAlertView alloc] initWithTitle:@"ADD item" message:@"Put it blank textfield will cover this" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    
    UITextField *txtName = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
    txtName.text=@"";
    [txtName setBackgroundColor:[UIColor whiteColor]];
    [txtName setKeyboardAppearance:UIKeyboardAppearanceAlert];
    [txtName setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    [txtName setTextAlignment:UITextAlignmentCenter];
    [createNewAlert addSubview:txtName];
    
    
    [createNewAlert show];
    }
    

    Also you can refer the following two methods which are called on Keyboard notifications.

    -(void)keyboardWillShow: (id) notification {
    
    if(showAlert==YES)
    {
    
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.3];
        [createNewAlert setTransform:CGAffineTransformMakeTranslation(0,-60)];
        [createNewAlert show];
        [UIView commitAnimations];
    }
    

    }

    -(void)keyboardWillHide: (id) notification {
    
    if(showAlert==YES) 
    {
    
    
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:0.3];
            [createNewAlert setTransform:CGAffineTransformMakeTranslation(0,+60)];
    
            [UIView commitAnimations];
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to add a custom pin for current location, However the location does not
I'm trying to format an UITextField as user types text, for instance to show
I am trying add OR operator in awk command. The following does not work.
I'm trying add data triggers to the default combobox style so each text item
I'm trying add a bold/strong tag the line headings of the follow string/text block:
Trying to add text to QGraphicsView: Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this);
I am trying add two columns in a text file that are seperated by
I'm trying to add a line of text to the middle of a text
i'm new to django and im trying add a user using django admin page.
I'm trying add Taskbar Icon overlay with text to windows7 application icon, I did

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.