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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:46:49+00:00 2026-06-14T06:46:49+00:00

Im having this problem for weeks already. because my app needs a function that

  • 0

Im having this problem for weeks already. because my app needs a function that will create a UITextfield, undo, and delete the UITexfield. my code create textfield anywhere on the view when you tap it. and it also can undo the last textfield that been created when pressed button undo, it can be move, scale, rotate also, but after i created another new textfield, the old one was been attached to the view. that is why when i long pressed the old textfield, it can be deleted only the new one that was been created can be delete. what will i do how to make that old textfield deleted?here my code.

ViewController.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>


@interface ViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate>
{

    NSMutableArray *textfieldform;//array for textfield
    UITextField *textField1;//a textfield
    CGPoint prevPanPoint;// float for moving the textfield anywhere
    float prevPinchScale;// float for pinching the textfield
    float prevRotation;// float for rotating the textfield
}


@property (nonatomic, retain) NSMutableArray *textfieldform;//array for creating multiple textfield


-(IBAction) undo;
- (IBAction)handleTap2:(UITapGestureRecognizer *)recognizer;
-(IBAction)panGestureAction:(UIPanGestureRecognizer *)pan;
- (IBAction)scaleImage:(UIPinchGestureRecognizer *)recognizer;
- (IBAction)rotateImage:(UIRotationGestureRecognizer *)recognizer;
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize textfieldform;
- (void)viewDidLoad{
    [super viewDidLoad];
    //textfieldform = [[NSMutableArray alloc] init];
  // Do any additional setup after loading the view, typically from a nib.
    textfieldform = [NSMutableArray arrayWithCapacity:0];//array of the textfield
}
//connected to the self.view
-(IBAction) longPressGesture:(UIGestureRecognizer*)gesture{
    [textfieldform removeObject:textField1];
    [textField1 removeFromSuperview];
    NSLog(@"baaaaaaam!");
}
//make the textfield move to any direction in the self.view
-(IBAction)panGestureAction:(UIPanGestureRecognizer *)pan {
    CGPoint translation = [pan translationInView:self.view];
    textField1.transform = CGAffineTransformTranslate(textField1.transform, translation.x, translation.y);
    [pan setTranslation:CGPointZero inView:self.view]; 
}

//to make the use of gesture simultaneously within the view
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
//to make the use of gesture simultaneously
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    if([touch.view isKindOfClass:[UIControl class]]) {
        return YES;
    }
    return NO;
}
//to pinch the textfield using 2 fingers.
- (IBAction)scaleImage:(UIPinchGestureRecognizer *)recognizer{

    textField1.transform = CGAffineTransformScale(textField1.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1;
}
//to rotate the textfield using 2 fingers
- (IBAction)rotateImage:(UIRotationGestureRecognizer *)recognizer{
    textField1.transform = CGAffineTransformRotate(textField1.transform, recognizer.rotation);
    recognizer.rotation = 0;
}
//to remove the last textfield that was been created
-(IBAction)undo{
    UITextField *textFieldToRemove = [textfieldform lastObject];
    if (textFieldToRemove) {
        [textfieldform removeObject:textFieldToRemove];
        [textFieldToRemove removeFromSuperview];
    }

}
// for the editing of the textfield 
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 

    NSLog(@"textFieldShouldBeginEditing");
    return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{           

    NSLog(@"textFieldDidBeginEditing");
    [textField1  setBackgroundColor:[UIColor colorWithRed:(248/255.0) green:(248/255.0) blue:(255/255.0) alpha:1.0]];
    textField1.borderStyle = UITextBorderStyleRoundedRect;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    NSLog(@"textFieldShouldEndEditing");
    textField.backgroundColor = [UIColor clearColor];
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{

    NSLog(@"textFieldDidEndEditing");
    [textField1  setBackgroundColor:[UIColor clearColor]];
    textField1.borderStyle = UITextBorderStyleNone;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    NSLog(@"textField:shouldChangeCharactersInRange:replacementString:");

    if ([string isEqualToString:@"#"]) {
        return NO;
    }
    else {
        return YES;
    }

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

    NSLog(@"textFieldShouldClear:");
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    NSLog(@"textFieldShouldReturn:");
    if (textField.tag == textfieldform.count) {
        textField1 = (UITextField *)[self.view viewWithTag:textfieldform.count];
        [textField1 becomeFirstResponder];
    }
    else {
        [textField resignFirstResponder];
    }
    return YES;
}
//when tap the user can create a textfield on any direction, it create many different textfield. according to how many tap you do on the view
- (IBAction)handleTap2:(UITapGestureRecognizer *)recognizer{
    if (recognizer.state == UIGestureRecognizerStateEnded){
        CGPoint point = [recognizer locationInView:[self view]];
        textField1 = [[UITextField alloc] init];
        textField1.borderStyle = UITextBorderStyleLine;
        [textField1 setAdjustsFontSizeToFitWidth:YES];
        [textField1 setText:@"TextField"];
        CGRect frame ;    
        frame.origin.x = point.x;
        frame.origin.y = point.y; 
        frame.size.width=200;
        frame.size.height=40;
        textField1.frame=frame;
        textField1.autocorrectionType = UITextAutocorrectionTypeNo;
        textField1.keyboardType = UIKeyboardTypeDefault;
        textField1.returnKeyType = UIReturnKeyDefault;
        textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
        textField1.delegate = self;
        textField1.tag = textfieldform.count;
        [textfieldform addObject:textField1];
        [self.view addSubview:textField1];
        [textField1 setAdjustsFontSizeToFitWidth:YES];
    }

}

- (void)viewDidUnload{
    [super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
  • 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-14T06:46:50+00:00Added an answer on June 14, 2026 at 6:46 am

    You are using wrong method DoAction as selector, instead use LongPressgesture method

    Update your code like following:

    - (void)viewDidLoad{
        [super viewDidLoad];
    
        textfieldform = [[NSMutableArray alloc] init];
        textField1  = ... // Initialize textfield
    
        UILongPressGestureRecognizer *holdRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressgesture:)];
        [holdRecognizer setMinimumPressDuration:2];
        [holdRecognizer setDelegate:self];
        [textField1 addGestureRecognizer:holdRecognizer];
    }
    
    - (void)LongPressgesture:(UILongPressGestureRecognizer *)recognizer
    {
        if (recognizer.state == UIGestureRecognizerStateEnded) {
            //[textfieldform removeObject: recognizer.view];
            [recognizer.view removeFromSuperview];
    
            NSLog(@"Long press Ended .................");
        }
        else {
            NSLog(@"Long press detected .....................");
        }        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that many people have had this problem... but I am now having
I'm having this problem for a while now. I tried so many things that
I've been having this design-pattern problem for weeks. Where do I put the logic
I have been having this problem for a couple of weeks now. The problem
I've having this problem with some JavaScript code. I've simplified it in the error
I'm having this problem where I keep getting this error in my console: *
I'm having this problem with the grails liferay-plugin: localhost_liferay_portlet_WEB_INF_grails_app_views_test_view_gsp: 17: expecting anything but ''\n'';
We are having this problem with a controller right now; the controller looks like
I'm having this problem on a new cruisecontrol.net install running on Windows Server 2003
So i'm having this problem. I have two tables (Oracle), one is called Destination

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.