UISearchBar 与 InputView

发布于 2024-11-03 05:57:51 字数 393 浏览 0 评论 0原文

我正在为我的应用程序制作自定义键盘,它与 UITextField 一起工作正常。但 UISearchBar 不支持 inputView

- (UIView *)inputView {
    if(self.keyboard==nil)
    {
        self.keyboard=[[[MMKeyboard alloc] initWithNibName:@"MMKeyboard" bundle:nil]autorelease];
    }
    NSLog(@"HERE");
    return self.keyboard.view;

}

如何在 UISearchBar 中替换我的自定义 UITextField 或如何在 UISearchBar 中实现 inputView ?

I'm making custom keyboard for my app and it's working fine with UITextField. But UISearchBar don't support inputView

- (UIView *)inputView {
    if(self.keyboard==nil)
    {
        self.keyboard=[[[MMKeyboard alloc] initWithNibName:@"MMKeyboard" bundle:nil]autorelease];
    }
    NSLog(@"HERE");
    return self.keyboard.view;

}

How to replace with my custom UITextField in UISearchBar or how to implement inputView in UISearchBar ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缘字诀 2024-11-10 05:57:51

正如此代码所做的那样,但您更改了 inputView

// loop around subviews of UISearchBar
for (UIView *searchBarSubview in [searchBar subviews]) {    
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {    
  @try {
    // set style of keyboard
    [(UITextField *)searchBarSubview setKeyboardAppearance:UIKeyboardAppearanceAlert];

    // always force return key to be enabled
    [(UITextField *)searchBarSubview setEnablesReturnKeyAutomatically:NO];
  }
  @catch (NSException * e) {        
    // ignore exception
  }
 }
}

有关更多详细信息,请参阅此帖子:

iphone UISearchBar 完成按钮始终启用

As this code is doing but you instead change the inputView:

// loop around subviews of UISearchBar
for (UIView *searchBarSubview in [searchBar subviews]) {    
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {    
  @try {
    // set style of keyboard
    [(UITextField *)searchBarSubview setKeyboardAppearance:UIKeyboardAppearanceAlert];

    // always force return key to be enabled
    [(UITextField *)searchBarSubview setEnablesReturnKeyAutomatically:NO];
  }
  @catch (NSException * e) {        
    // ignore exception
  }
 }
}

See this post for more details:

iphone UISearchBar Done button always enabled

吻风 2024-11-10 05:57:51

我解决如下

#import <Foundation/Foundation.h>
#import "MMKeyboard.h"

@interface MMSBar : UISearchBar {
    MMKeyboard* keyboard;

}
@property(nonatomic,retain)MMKeyboard* keyboard;

@end




- (void)layoutSubviews {

    if(self.keyboard==nil)
    {
        self.keyboard=[[[MMKeyboard alloc] initWithNibName:@"MMKeyboard" bundle:nil]autorelease];
    }


    UITextView *searchField;
    NSUInteger numViews = [self.subviews count];
    for(int i = 0; i < numViews; i++) {
        if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
            searchField = [self.subviews objectAtIndex:i];
            [searchField setInputView:keyboard.view];
        }
    }

    [super layoutSubviews];
}

I solved like following

#import <Foundation/Foundation.h>
#import "MMKeyboard.h"

@interface MMSBar : UISearchBar {
    MMKeyboard* keyboard;

}
@property(nonatomic,retain)MMKeyboard* keyboard;

@end




- (void)layoutSubviews {

    if(self.keyboard==nil)
    {
        self.keyboard=[[[MMKeyboard alloc] initWithNibName:@"MMKeyboard" bundle:nil]autorelease];
    }


    UITextView *searchField;
    NSUInteger numViews = [self.subviews count];
    for(int i = 0; i < numViews; i++) {
        if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
            searchField = [self.subviews objectAtIndex:i];
            [searchField setInputView:keyboard.view];
        }
    }

    [super layoutSubviews];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文