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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:08:18+00:00 2026-05-22T18:08:18+00:00

I want to put something like this in a method for UITextField & UITextView

  • 0

I want to put something like this in a method for UITextField & UITextView.

- (void)changeKeyboardType:(UIKeyboardType)keyboardType {
    paymentTextView.keyboardType = UIKeyboardTypeAlphabet;
    [paymentTextView resignFirstResponder];
    [paymentTextView becomeFirstResponder];
}

How do I do this? I know I can create categories for both UITextField & UITextView but is it possible to do it in one shot?

By one shot, I mean add it to both classes with one protocol instead of making two categories, one for UITextView & one for UITextField. I’ve heard a protocol is similar to a Ruby module, but in a Ruby module, I can implement the method. In a protocol, it only seems that I can declare the method but not implement it. Can I also implement the method in the protocol, and then include this protocol in UITextField & UITextView?

How to add a method to an existing protocol in Cocoa? is close but not quite.

  • 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-22T18:08:18+00:00Added an answer on May 22, 2026 at 6:08 pm

    What about something like this?

    // UIView+UITextInputTraits.h
    
    @interface UIView (UITextInputTraits)
    - (void)changeKeyboardType:(UIKeyboardType)keyboardType;    
    @end
    
    
    // UIView+Additions.m
    
    #import "UIView+UITextInputTraits.h"
    
    @implementation UIView (UITextInputTraits)
    
    - (void)changeKeyboardType:(UIKeyboardType)keyboardType {
        if ([self conformsToProtocol:@protocol(UITextInputTraits)]) {
            id<UITextInputTraits> textInput = (id<UITextInputTraits>)self;
            if (textInput.keyboardType != keyboardType) {
                [self resignFirstResponder];
                textInput.keyboardType = keyboardType;
                [self becomeFirstResponder];
            }
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put the result of this: std::tr1::mem_fn(&ClassA::method); Inside a variable, what is
I want to process something using parallel loop like this : public void FillLogs(IEnumerable<IComputer>
I have something like this: void GenerateReports() { foreach (var employee in employees) {
i want to put the id into the colorbox below this code nom works
I have a method like this: private static double ComputePercentage(ushort level, ushort capacity) {
I'm trying to create an .on() method using events-map. I want to change this:
I'm writing a simple button class, something like this: @interface MyButton : NSObject {
I've my Model something maybe like this : public class Person { public virtual
Let's say I have a function that looks like this: public void saveBooking(/* some
i want to put set of standart constraints (like not null alphanumeric string with

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.