Как отключить / включить ключ возврата в UITextField?

class Program {
    static void Main(string[] args) {
        string input = "";
        List<List<int>> answers = new List<List<int>>();
        int questionsCount = ReadInt32("The number of questions: ");
        for (int i = 0; i < questionsCount; i++) {
            answers.Add(new List<int>());
        }
        while (input == "" || input == "y") {
            for (int i = 0; i < answers.Count; i++) {
                List<int> a = answers[i];
                a.Add(ReadInt32($"Question [{i}]: "));
            }
            input = Read("Continue (y/n)? ").ToLower();
        }
        WriteLine("End of input!");
        for (int i = 0; i < answers.Count; i++) {
            List<int> a = answers[i];
            Write($"Average for question[{i}]: {a.Average()}\n");
        }
        ReadKey();
    }

    static string Read (string a) {
        Write(a);
        return ReadLine();
    }

    static int ReadInt32 (string a = "") {
        Write(a);
        return ToInt32(ReadLine());
    }
}

Попробуйте это. Вы можете настроить вопросы. И обратите внимание, что для использования Write() и WriteLine(), вы должны добавить

using static System.Console;

вверху, в ссылках проекта.

67
задан Jonathan Soifer 14 May 2016 в 19:02
поделиться

2 ответа

If you can get the UIKeyboard object itself (something not exposed in the SDK, mind you, so Apple may not be happy if you use these calls), then there's a convenient setReturnKeyEnabled: member function.

id keyboard = [self magicallyGetAUIKeyboardInstance];
[keyboard setReturnKeyEnabled: NO];

(via Erica Sadun's dump of the 2.2 iPhone frameworks)

The implementation of magicallyGetAUIKeyboardInstance is described here.

23
ответ дан 24 November 2019 в 14:33
поделиться

Хорошая идея - создать один файл для доступа к этому классу из любого места. Вот код:

UIKeyboard.h

#import <UIKit/UIKit.h> 

@interface UIApplication (KeyboardView)

    - (UIView *)keyboardView; 

@end

UIKeyboard.m

#import "UIKeyboard.h"

@implementation UIApplication (KeyboardView)

- (UIView *)keyboardView
{
    NSArray *windows = [self windows];
    for (UIWindow *window in [windows reverseObjectEnumerator])
    {
        for (UIView *view in [window subviews])
        {
            if (!strcmp(object_getClassName(view), "UIKeyboard"))
            {
                return view;
            }
        }
    }

    return nil;
}

@end

Теперь вы можете импортировать и получить доступ к этому классу из вашего собственного класса:

#import "UIKeyboard.h"

    // Keyboard Instance Pointer.
    UIView *keyboardView = [[UIApplication sharedApplication] keyboardView];

Полную документацию по этому классу вы можете найти здесь: http://ericasadun.com/iPhoneDocs/_u_i_keyboard_8h-source.html

Более подробную информацию можно найти здесь: http://cocoawithlove.com/2009/04/showing-message-over-iphone-keyboard. html

3
ответ дан 24 November 2019 в 14:33
поделиться