带有InputView的UISearchBar [英] UISearchBar with InputView

查看:96
本文介绍了带有InputView的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;

}

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

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

推荐答案

我解决了如下

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

这篇关于带有InputView的UISearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆