Ignore Tab character in UITextField… (iPad app)

前端 未结 5 773
难免孤独
难免孤独 2021-01-17 09:39

I have a TableView with TextFields in each cell and I want to those textfields ignore the character tab (\\t).

When the tab key is pressed, the t

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 10:09

    Implement this method:

    Add this in your AppDelegate.m

    - (NSArray *)keyCommands {
    static NSArray *commands;
    
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        UIKeyCommand *const forward = [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:0 action:@selector(ignore)];
        UIKeyCommand *const backward = [UIKeyCommand keyCommandWithInput:@"\t" modifierFlags:UIKeyModifierShift action:@selector(ignore)];
    
        commands = @[forward, backward];
    });
    
    return commands;
    }
    

    Add this method in the ViewController.m or subclass of UITextField in which you want to handle the TAB key event

    - (void)ignore {
    
        NSLog(@"Your Action");
    } 
    

    Described in: How do you set the tab order in iOS?

提交回复
热议问题