UIKeyCommands无法正常工作

时间:2016-02-21 14:14:28

标签: ios objective-c uikeycommand

我正在尝试将iPad的自定义快捷方式添加到我的应用中。但是,使用下面的代码我无法看到它们正常工作。当我按下命令键时,我得到发现模式,但是当我按下命令+ f时没有任何反应。我做错了什么?

#pragma mark - UIResponder

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (NSArray *)keyCommands {
    return @[
         [UIKeyCommand keyCommandWithInput:@"f" modifierFlags:0 action:@selector(backspacePressed:) discoverabilityTitle:@"New message"]
    ];
}

- (void)backspacePressed:(UIKeyCommand *)command {
    NSLog(@"Backspace key was pressed");
}

1 个答案:

答案 0 :(得分:1)

原来,为了让我能够注册cmd + f,我需要将/** * Return the number of characters that the two strings overlap * @param str1 * @param str2 * @param min - minimum required overlap * @return The number they actually overlap for first detected overlap */ static int numOverlap(String str1, String str2, int min) { int pos = getOverlap(str1, str2, min); if (pos < 0) { return -1; } char a[] = str1.toCharArray(); char b[] = str2.toCharArray(); int i = 0; while (a[i + st1Pos] == b[i + st2Pos]) { i++; if ((i + st1Pos >= a.length) || (i + st2Pos >= b.length)) { break; } } return i; } $.ajax({ url: path, method: 'GET', async: true, success:function(data) { $(this.$modal).append(data); //-- call the form js theFormData(); }) }); function theFormData(){ //-- add your code here, this should now be able to bind to your form as it //-- has something to hook onto } 更改为ko.applyBindings({});

<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>
<div class="span6 actions-panel-bottom" data-bind="css: {
                                         'make-primary': (lalal.viewModels.transacFilterTabsViewModel.getSyncList().resultsetLength() > 0 && !lalal.viewModels.transacQuickactionsViewModel.operationInProgress() && (lalal.viewModels.transacFilterTabsViewModel.getSyncList().captureButtonIsEnabled() || lalal.viewModels.transacFilterTabsViewModel.getSyncList().refundButtonIsEnabled()|| lalal.viewModels.transacFilterTabsViewModel.getSyncList().abortButtonIsEnabled()))"></div>