【问题标题】:UISearchBar with InputView带有 InputView 的 UISearchBar
【发布时间】:2011-08-11 19:36:43
【问题描述】:

我正在为我的应用程序制作自定义键盘,它可以与 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 ?

【问题讨论】:

  • 有任何关于您的问题的消息吗?

标签: iphone keyboard inputview


【解决方案1】:

正如这段代码所做的那样,但您改为更改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 Done button always enabled

【讨论】:

    【解决方案2】:

    我解决了如下

    #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];
    }
    

    【讨论】:

    • 这种方式会不会对苹果的审核流程没有问题?
    • 我的应用没有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多