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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:21:29+00:00 2026-05-30T07:21:29+00:00

I have the following code: -(void)textFieldDidBeginEditing:(UITextField *)textField { CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];

  • 0

I have the following code:

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
...

}

As you can see it passes in a UITextField. I also have this code duplicated in the same ViewController but passing in a UITextView.

I want to be able to refactor this into a single method which passes in either the UITextField or UITextView? How can I do this?

Also this code appears in other View Controllers, so ideally I’d like to place it in a helper class, very new to iOS so not sure where to go from here.

I’ve removed most of the code from the method for brevity, but what it does is it slides the UI controls into view when the iOS keyboard appears.

  • 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-30T07:21:30+00:00Added an answer on May 30, 2026 at 7:21 am

    You can expect UIView, as it seems you don’t use any special text properties from those views.

    -(void)textFieldDidBeginEditing:(UIView *)textField
    {
        CGRect textFieldRect = [self.view.window convertRect:textField.bounds fromView:textField];
        CGRect viewRect = [self.view.window convertRect:self.view.bounds fromView:self.view];
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code... - (void)textFieldDidBeginEditing:(UITextField *)textField { //some code here... NSInteger theTag
I have the following code - (void) viewWillAppear:(BOOL)animated { NSLog(@dismiss view); [self dismissModalViewControllerAnimated:YES]; }
Using a split view on the iPad, I have the following code: - (void)
just stuck with strange thing. I have the following code: -(void)ImageDownloadCompleat { [self performSelectorOnMainThread:@selector(updateImageButton:)
I have the following code: - (void)drawRect:(NSRect)dirtyRect { [[NSBezierPath bezierPathWithOvalInRect:[self theRect]] stroke]; } -
I have following code: private void ProcessQueue() { foreach (MessageQueueItem item in GetNextQueuedItem()) PerformAction(item);
I have the following code: void foo() { vector<double> v(100,1); // line 1 //
I have following code: public static void ProcessStep(Action action) { //do something here if
I have the following code: public void BeginConvert(object data) { ConverterData cObject = (ConverterData)data;
I have the following code: public void post(String message) { final String mess =

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.